loop362 has asked for the wisdom of the Perl Monks concerning the following question:

Aloha, I have a very newbie question. My script can NOT read the first line of a data file. The file contains only four lines saying what line number it is. As you can see I am very new to PERL. My script is at: http://joeguillaume.com/FFD_folder/index.html Mahalo, Joseph W. Guillaume http://joeguillaume.com/

20050505 Unconsidered by Corion: " holli: insert the code from the url as long as it is there.", Votes: 9/11/2

Replies are listed 'Best First'.
Re: Can't Read First Line
by dynamo (Chaplain) on May 05, 2005 at 00:23 UTC
    Here's your loop:
    while(<JOE>) { @data = <JOE>; }
    each time through the loop, the <JOE> in the while loop reads a line of data into $_. You do nothing with the contents of $_ in the loop, so the first line is effectively lost.

    The @data=<JOE> line actually reads ALL remaining lines into the array. When this happens, it causes the next test for the while() to come out false, since there are no more input lines to process.

    So, I think all you really want here is to remove the while loop, replacing the above code with:

    @data = <JOE>;

    For the record, this would also work, and would conceptually be closer to what you were trying to do (but would be less elegant / perl-ish):

    while(<JOE>) { push @data, $_; }

    BTW, your code is very short, next time if it's like that, I suggest you just paste the code into your post rather than link to it. Same with the results.

Re: Can't Read First Line
by loop362 (Pilgrim) on May 05, 2005 at 01:58 UTC
    Thank you very much!