Hi all!
I've run into a strange issue with a global array that is being populated by values that (on the face of it) I can't figure out why.
I'm using strict/warnings, and have used Data::Dumper to find the point where the value of my global array is changing. Basically, I have a global array of hashes, with each key being the "type" of a regular expression (I have multiple regular expressions to run on a certain file type, with each regular expression looking for/at a specific part of the file) . The global array is declared at the top of the script:
my @regexes = ();In a foreach loop within a subroutine, I make a call to another sub:
foreach (@regexes){ ($fileBodyMatch, $decode ) = checkFileBody ($file, $_->{bodyregex}); }
The array looks fine before this subroutine call. The value of "$decode" is what I'd expect it to be. In the subroutine checkFileBody, I do the following ($filename is the $file value being passed in) :
open ( DKT, "gunzip -c $filename | ") or die "Can't open pipe to $file +name\n";
At this point, everything still looks good in Dumper. I then do this:
while (<DKT>){ my $line =$_; #process data in here }
Even before I have the "my $line" declaration I have a Data Dumper call to print out the contents of @regexes and the @regexes array contains the last line of the file read and nothing else.
At the conclusion of the sub, the net result is that the @regexes array contains the last line of the file as the first element of the array, followed by the previous (valid) contents.
Thank you in advance!
In reply to Strange Global Array issue by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |