in reply to how to print first 5 lines of a file

Why does no-one ever use the flip-flop operator for this?

while (<>) { print if 1 .. 5; }

Blessed Be
The Pixel

Replies are listed 'Best First'.
Re: Re: how to print first 5 lines of a file
by blakem (Monsignor) on Nov 01, 2001 at 13:59 UTC
    Nice, but that still loops over the entire file... I'd exit out of the loop after the fifth line like so:
    while(<>) { 1 .. 5 ? print : last; }

    -Blake