in reply to peeling the top 10 lines from a file

You are missing the sigil at "counter <10". You would have spotted this if you used strict;
use strict; my $counter=0; print"TOP\n"; while( $counter++<10) { last if eof(STDIN); $_=<>; print "$counter $_"; } print "BOTTOM";
Update:

More caveats:
The second part of your conditional will never be checked because the first part is always true, unless the end of the file is reached.
Furthermore it seems the <> does not assign the read line to $_ when there is a && afterwards.
I don't know why. Anyone can explain that?

Update: Silliness striked. Thanks Roy_Johnson.


holli, /regexed monk/

Replies are listed 'Best First'.
Re^2: peeling the top 10 lines from a file
by davido (Cardinal) on May 16, 2005 at 15:50 UTC

    The problem with his while( (<>) && $counter < 10 ) {... (besides the fact that he's missing a sigil) is apparent when you turn on warnings and look at the output. Once you add the logical short circuit, the magic while(<>) is lost, and you end up with a plain old boolean evaluation of the <> operator. That results in two problems.

    First, $_ doesn't receive the current line of the file without explicitly assigning it. Try it with warnings and you'll see "Uninitialized value....." warnings for each line. Second, as the warnings also state, "Value of handle construct can be "0", test with defined()."


    Dave

Re^2: peeling the top 10 lines from a file
by reasonablekeith (Deacon) on May 16, 2005 at 15:47 UTC
    Perlnut says that $_ is only populated when a line-input operator is the sole critereon of the while test.

    which reads as, like it or lump it. :-)

    Update: Perlnut being my own personal shortcut for "Perl in a Nutshell".

    ---
    my name's not Keith, and I'm not reasonable.