in reply to Finding number of lines in STDIN

There's a perl variable which counts lines on a filehandle, and works on STDIN, it's called $.. So just do something like:
last if($. == $number_of_lines);
(To compare numbers, use '==' not 'eq')

Note: $. is the line count for the last filehandle accessed, so dont use it if you're accessing other files inbetween.

C.

Replies are listed 'Best First'.
Re: Re: Finding number of lines in STDIN
by ysth (Canon) on Dec 18, 2003 at 16:32 UTC
    Clarification: $. is the line count for the last filehandle accessed by and of: readline (aka <>), tell(FILEHANDLE), seek, or sysseek.

    You can access the line count for any filehandle with some_filehandle->input_line_number (but you have to use FileHandle or use IO::Handle first).

    Note that STDIN->input_line_number is tracked separately from ARGV->input_line_number even when <ARGV> or empty <> is reading from stdin.