in reply to mod_perl - local vs my...
For starters, don't use prototypes unless required. In other words, drop the () on the sub line.
It would probably be better to pass the file name as a parameter.
You should localize your file handle.
I see that @lines is not declared either. I don't see any reason for this to be a global. This is probably the reason you're seeing the wrong config file.
sub read_the_config { my ($file) = @_; my @lines; local *CFG; open(CFG, "<$file") || log_error("Problem reading $file - $!"); while (<CFG>) { ... return \@lines; }
In newer version of Perl (don't know which exactly, but <updated>at least since 5.6.1</updated>), you can get rid of the local completely:
sub read_the_config { my ($file) = @_; my @lines; my $cfg_fh; open($cfg_fh, "<$file") || log_error("Problem reading $file - $!"); while (<$cfg_fh>) { ... return \@lines; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: mod_perl leaking variables?
by JediWizard (Deacon) on Nov 09, 2004 at 14:54 UTC |