You can't nest implicit while(<FH>) loops - both clobber the global $_ variable. If you're going to use nested while(<FH>) loops then you need to assign to a different variable or localize $_ before entering the inner while(). The easiest (but not the best) thing to do is just to localize $_ for the block. I copied right from your code, put this section in a block and localized both $_ and the filehandle (you know to do that too, right?).

I also reversed your arguments to split() since you had those backwards and I removed the `undef @ary` line since that just wastes everyone's time. The my() call earlier in the loop already scopes the array to that block and ensures it is new each time the loop restarts.

{ local $_; local *INPUT; open(INPUT, "invalid") || die "Cannot open invalid input ( +invalid) for reading ($!)\n"; while(<INPUT>) { next if($_ =~ m/^#/); my @curr_invalid = split(/\t/, $_); $invalid{$curr_invalid[1]} = $invalid{$curr_invalid[1] +} . "\t" . $curr_invalid[0]; } close INPUT; }

In reply to Re: File I/O Slow Down by diotalevi
in thread File I/O Slow Down by agentsim

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.