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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |