|Do you know where your variables are?|
Strange Global Array issueby Anonymous Monk
|on Apr 16, 2013 at 14:34 UTC||Need Help??|
Anonymous Monk has asked for the
wisdom of the Perl Monks concerning the following question:
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:
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) :
At this point, everything still looks good in Dumper. I then do this:
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!