From: Dennis G. <dg...@re...> - 2004-05-13 17:30:20
|
In my patch I added a block around the code and made $/ local. However, now that I look back at the patch I see that I have the files in reverse order, so I see the confusion. Sorry about that. I've attached a new patch with the files in the correct order. -- Dennis On Thu, 2004-05-13 at 13:07, Mike Schilli wrote: > Dennis Gregorovic wrote on 5/13/2004, 7:41 AM: > > > In this line: > > > > @text = <TEXT>; > > > > it is assuming that $/ is set to "\n", which would result in @text > > containing an entry for each line in the config file. > > Ah, ok, now I understand. However, tinkering with $/ without limiting > its scope is considered bad style. "perldoc perlvar" shows: > > But the following code is quite bad: > > open my $fh, "foo" or die $!; > undef $/; # enable slurp mode > my $content = <$fh>; > close $fh; > > since some other module, may want to read data from some file in the > default "line mode", so if the code we have just presented has been > executed, the global value of $/ is now changed for any other code > running inside the same Perl interpreter. > > Usually when a variable is localized you want to make sure that this > change affects the shortest scope possible. So unless you are already > inside some short "{}" block, you should create one yourself. For > example: > > my $content = ''; > open my $fh, "foo" or die $!; > { > local $/; > $content = <$fh>; > } > close $fh; > > So, regarding Log4perl: unless anyone has any strong opinion about this, > I'd rather leave it as it is for now. > > -- > -- Mike > Mike Schilli > m...@pe... > |