in reply to Re^5: What does this mean
in thread Code explanation needed (was: What does this mean)

Funny thing is, Larry added labels and the {last|next|redo} LABEL syntax to avoid having code with temporary variables like yours.... Do a man perlsyn and skip to "Here's how a C programmer might code".

Abigail

Replies are listed 'Best First'.
Re^N+1: What does this mean
by tadman (Prior) on Jun 10, 2002 at 15:12 UTC
    To address that specific example, if you re-wrote it as a subroutine, you could just return and be done with it. There is no need for a last LABEL when you do something like that.
    sub foo { my ($ary1, $ary2) = @_; foreach my $wid (@$ary1) { foreach my $jet (@$ary2) { last if ($wid > $jet); $wid += $jet; } } return; } foo(\@ary1, \@ary2);
    Sure, you can use LABELs to reduce what I might term "flag variables", or variables that merely represent a condition, but with a little re-engineering, you can usually eliminate those and still not use LABELs.

    Update:
    I had put a return if ($wid > $jet); but this was incorrect, and this would explain why my remarks seem kind of incoherent.
      I guess you missed the It's safer because if code gets added between the inner and outer loops later on, the new code won't be accidentally executed in the documentation.

      Your "put it in a sub" is a red herring. It doesn't add anything (after all, your return is outside the outer loop anyway.

      Abigail