in reply to understanding next
You want to loop over the whole array and then test if certain conditions were met (and how often).
You need to detect if a loop exited early.my @l_test = (1,2,3,4,5,6,7); my $found; foreach my $l_rec (@l_test) { $found++, next if $l_rec == 4; print $l_rec; } print qq{\nskipped 4\n} if $found;
my @l_test = (1,2,3,4,5,6,7); my ($found, $bad); foreach my $l_rec (@l_test) { $found++, next if $l_rec == 8; $bad++, last if $l_rec > 10; print $l_rec; } die qq{8 found\n} if $found; die qq{high number found\n} if $bad;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: understanding next
by ruzam (Curate) on Jan 31, 2008 at 13:53 UTC |