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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.