in reply to for loop ?

This use of 'for' is unusual, but early perl's did not really have a switch/case statement. Nowadays we would use given and when.

The 'for' loop loops over each item in its list (the variables inside parentheses). In each for loop there is only one item in the list, so they would only go through one iteration.

Replies are listed 'Best First'.
Re^2: for loop ?
by DrHyde (Prior) on Aug 11, 2011 at 10:15 UTC
    We did, however, have if ... elsif ... else in the "bad old days", which would be a better approach than abusing a looping construct. Using for like this just makes the code harder to read than it should be.
      So far as I know we still have if ... elsif ... else. Personally I would not even think of using a for loop in this way, which means I learnt something. I'm all for trying different code tricks, some are dire and should be destroyed at birth, but some bring enlightenment.
      I'm not sure that the code is any harder to read than some of the attempts at switch/case using LABELS (as in the Perl Cookbook). I agree with your sentiment though, and grateful that we have been blessed with given/when.