http://www.perlmonks.org?node_id=1043559


in reply to wantarray alternative

context is propagated into the return statement.

see Context propagation into subs and evals

and according to perldoc: map in scalar context, returns the total number of elements so generated.

But the following code forces the map-statement into a sliced list.

DB<156> sub tst { (map {lc} @_)[0.. wantarray * $#_] } DB<157> @list=tst("A".."D") => ("a", "b", "c", "d") DB<158> $scalar=tst("A".."D") => "a"

and if the last value is enough for you in scalar context do

DB<159> sub tst { (map {lc} @_)[0.. $#_] } DB<160> @list=tst("A".."D") => ("a", "b", "c", "d") DB<161> $scalar=tst("A".."D") => "d"

you haven't answered my question in Re^5: wantarray alternative yet, so you have both alternatives now.

Cheers Rolf

( addicted to the Perl Programming Language)