in reply to Line number problem with foreach

This worked for me:

open my $fh, "test.txt" or die $!; while(<$fh>) { print "$.:$_"; } __END__ outputs: 1:First line 2:Second line 3:Third line 4:Fourth line

Replies are listed 'Best First'.
Re^2: Line number problem with foreach
by vinoth.ree (Monsignor) on Feb 28, 2009 at 04:44 UTC

    I know while loop will work. But I wanted why it is behaving differently with foreach.