foreach my $num (split /::/ => $value) {
####
my @value_tokens = split /::/, $value;
foreach my $value_token (@value_tokens) {
####
Here's how a C programmer might code up a particular algo-
rithm in Perl:
rithm in Perl:
for (my $i = 0; $i < @ary1; $i++) {
for (my $j = 0; $j < @ary2; $j++) {
if ($ary1[$i] > $ary2[$j]) {
last; # can't go to outer :-(
}
$ary1[$i] += $ary2[$j];
}
# this is where that last takes me
}
Whereas here's how a Perl programmer more comfortable with
the idiom might do it:
OUTER: for my $wid (@ary1) {
INNER: for my $jet (@ary2) {
next OUTER if $wid > $jet;
$wid += $jet;
}
}
See how much easier this is? It's cleaner, safer, and
faster. It's cleaner because it's less noisy. It's safer
because if code gets added between the inner and outer
loops later on, the new code won't be accidentally exe-
cuted. The "next" explicitly iterates the other loop
rather than merely terminating the inner one. And it's
faster because Perl executes a "foreach" statement more
rapidly than it would the equivalent "for" loop.
####
if $found:
next;
}