in reply to Putting files in an Array
ARGV in the while condition needs a '@'. Did you ever try to execute the script? UPDATE: Please ignore this line, I must have been in auto-destruct mode ;-). Thanks monsoon for the speedy correction
Naturally you could use a hash as well. Whether it works better with a hash or an array depends on what you need to do with the data. It also depends on the data. Since you only put lines into @results if they have "head" somewhere in the line and your example text file has not one line with "head" in it, an empty hash is as good as an empty array ;-)
PS: Your script seems to be a copy of a script suggested to you in this thread Out of Memory in Perl. I hope Zentara forgives me for saying this, but his advice to use @ARGVs magic just to read a file line by line is misleading. First of all it won't work to save memory by reading a file line by line if you then store it into an array anyway. And secondly you can read a file line by line without using @ARGV magic
Your original script (with the bug corrected) would have done the job as well.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Putting files in an Array
by monsoon (Pilgrim) on Jul 11, 2012 at 15:31 UTC | |
Re^2: Putting files in an Array
by zentara (Archbishop) on Jul 11, 2012 at 17:57 UTC |