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.


In reply to Re: Putting files in an Array by jethro
in thread Putting files in an Array by maheshkumar

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.