vsespb has asked for the wisdom of the Perl Monks concerning the following question:
According to perldoc http://perldoc.perl.org/functions/map.html
map should evaluate BLOCK in list context
but I am wondering why in my example, sometimes it's LIST context, sometimes SCALAR.Evaluates BLOCK or EXPR in list context
print "A:"; print map { /(\S+)/g or die } qq{ab cd}; # prints "A:1" so evaluated i +n scalar context print "\n"; print "B:"; print map { /(\S+)/g } qq{ab cd}; # prints "B:abcd", means evaluated +in list context print "\n"; print "C:"; for (qq{ab cd}) { print /(\S+)/g or die; # prints "C:abcd", list context again } print "\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: map BLOCK evaluation context
by tobyink (Canon) on Mar 08, 2013 at 14:20 UTC | |
by vsespb (Chaplain) on Mar 08, 2013 at 14:37 UTC | |
by tobyink (Canon) on Mar 08, 2013 at 14:50 UTC | |
by vsespb (Chaplain) on Mar 08, 2013 at 14:51 UTC | |
by Athanasius (Archbishop) on Mar 08, 2013 at 15:43 UTC | |
by vsespb (Chaplain) on Mar 08, 2013 at 16:09 UTC | |
by ikegami (Patriarch) on Mar 09, 2013 at 18:43 UTC | |
|
Re: map BLOCK evaluation context
by grondilu (Friar) on Mar 08, 2013 at 14:21 UTC |