in reply to Unhappy returns
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Unhappy returns
by thor (Priest) on Oct 10, 2005 at 11:59 UTC | |
by Perl Mouse (Chaplain) on Oct 10, 2005 at 12:53 UTC | |
by Aristotle (Chancellor) on Oct 10, 2005 at 14:33 UTC | |
by ysth (Canon) on Oct 10, 2005 at 15:23 UTC | |
by Aristotle (Chancellor) on Oct 10, 2005 at 15:30 UTC | |
| |
by sauoq (Abbot) on Oct 10, 2005 at 17:01 UTC | |
|