in reply to Re: Re: Insensitive Scoundrel
in thread Insensitive Scoundrel

It's almost as if pop and shift should work on scalars, don't you think? Then you can ditch chop as being silly.

You have a bit of a point, but for is a lot more than just map. It does different things. For example:
for my $foo (@bars) { next if ($foo > 10); last if ($foo == 42); $foo += 12; }
Now, what would you expect that loop to return, if it were like a map? You can't skip or restart map in the same way, you realise, probably because it could cause some very strange behavior.

I'm all for condensation where it makes sense, but in this case, I think you're going to have a Swiss-Army-like function and no heavy lifting tools.

Replies are listed 'Best First'.
Re^4: Insensitive Scoundrel
by John M. Dlugosz (Monsignor) on Sep 27, 2002 at 14:42 UTC
    That is my position: pop/shift/unshift/push are already understood and can be applied to strings. Someone else sais that it would be great if a string could appear to be an array of chars, in general.
map and foreach are the same
by John M. Dlugosz (Monsignor) on Oct 03, 2002 at 19:03 UTC
    Re: Now, what would you expect that loop to return, if it were like a map? You can't skip or restart map in the same way, you realise, probably because it could cause some very strange behavior.

    I got it: You have next, last, continue to modify the looping. How about a keyword result or somesuch that is like the "return" from a function? Just give an argument to next, continue, etc. and you don't need new keywords.

    Dropping off the end of the block is an implicit "continue", just as the last statement in a function is an implicit "return". If you don't give an argument to the next, last, or whatnot, it becomes an undef empty list and doesn't add anything to the result list.

      Just a minor nitpick: not giving an argument should implicitly pass the empty list, not undef - just like you do when you want an iteration of a map to "disappear" from the result list. </nitpick> :-)

      Makeshifts last the longest.