It is worth noting, however, that, contrary to map, grep evaluates its second argument in scalar context:And contrary to grep and map, foreach evaluates its body in void context:
$ perl sub ctx { print wantarray ? "list" : defined wantarray ? "scalar" : "v +oid" } @x = (1); print "map:"; map ctx, @x; print "\ngrep:"; grep ctx, @x; print "\nfor:"; ctx for @x; __END__ map:list grep:scalar for:void
In reply to Re: Unhappy returns
by ysth
in thread Unhappy returns
by tlm
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |