in reply to While behavior

The first while calls the match in list context, you get all matches but grab only the first line.

Since the string is exhausted the loop starts from the beginning and the match is never empty.

while normally imposes scalar context but you broke the logic.

update

just try grabbing more vars to understand what is happening

DB<118> while (my ($line1,$line2) = $data =~ m/^(.*)$/gm) { print "$ +line1 $line2\n"; last if $x++>5 } some random some random some random some random some random some random some random

Cheers Rolf

( addicted to the Perl Programming Language)

Replies are listed 'Best First'.
Re^2: While behavior
by SavannahLion (Pilgrim) on Feb 15, 2014 at 04:45 UTC

    Actually that does help. It also puts things like while(<FH>) in a better context.