in reply to Problems with map(function, array)
Nothing to do with map really. uc has magic!
In the following construct, uc is getting called with no parameters:
my @caps = map uc, @lower;
As per perlfunc, when called with no parameters, uc operates on $_. So you need to make your function act the same (as indeed you did in your second experiment).
From Perl 5.10 and above, there's a better technique to write such functions:
sub my_uc (_) { # note underscore in parentheses my $c = shift; return uc($c); }
And now my_uc has the same magic as uc.
perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Problems with map(function, array)
by Redei (Initiate) on Dec 12, 2012 at 14:06 UTC |
In Section
Seekers of Perl Wisdom