Hena has asked for the wisdom of the Perl Monks concerning the following question:
And data-file for it.#!/usr/bin/perl # # testing last # use strict; use warnings; my $i=0; my $file="test.file"; foreach my $count (1 .. 10) { open (INF,"$file") or die "Unable to open '$file': $!"; $i++ && m/2/ && last while (<INF>); close INF; $i=0; print "here:$count\n" } print "END($i)\n"; exit;
1 2 3 4Now when running the program ($i is line-count). Last actually ends the foreach loop, even though it should (at least I think so) end the while loop. However, if the while loops line is changed to this.
It prints correct output. So is this how it should work? My version of perl is 5.8.0 for RedHat 9.0.m/2/ && $i++ && last while (<INF>);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Last oddity
by PodMaster (Abbot) on Oct 21, 2004 at 09:08 UTC | |
by Hena (Friar) on Oct 21, 2004 at 11:56 UTC | |
|
Re: Last oddity
by Anonymous Monk on Oct 21, 2004 at 09:13 UTC | |
by Hena (Friar) on Oct 21, 2004 at 11:57 UTC |