in reply to Terminating Read Of Input

See last

while (my $line = <$fh>) { chomp($line); last if ($line =~ /TOTAL COMMAND SUMMARY/); my ($uid, $login, $cpupr, $cpunpr, @data) = (split("\t",$line)); }

(Update: execute last prior to split.)

Replies are listed 'Best First'.
Re^2: Terminating Read Of Input
by tirwhan (Abbot) on Aug 14, 2007 at 13:50 UTC

    And to make your intention slightly more obvious you can label the loop:

    READ_TILL_TOTAL: while (my $line = <$fh>) { chomp($line); last READ_TILL_TOTAL if ($line =~ /TOTAL COMMAND SUMMARY/); my ($uid, $login, $cpupr, $cpunpr, @data) = (split("\t",$line)); }

    This is especially helpful if you've got other loops around this block, for example a loop that opens a list of files and reads them all in turn.


    All dogma is stupid.
Re^2: Terminating Read Of Input
by SuicideJunkie (Vicar) on Aug 14, 2007 at 14:56 UTC
    Since this is a while loop, why not just put the check in the while condition?
    while( my $line = <$fh> and $line !~ /TOTAL COMMAND SUMMARY/) { ... }