On Sun, Nov 24, 2002 at 01:09:26PM -0500, George Schlossnagle wrote:
> It's also worth noting that it can modify your original array in place
True, but I think this is more suited to C.
> @a = ('bob','jane');
> map {$_ = ucfirst($_)} @a;
$_ = ucfirst for @a;
> This can be useful (or painful
It's also worth noting that it can modify your original array in place
@a = ('bob','jane');
map {$_ = ucfirst($_)} @a;
This can be useful (or painful if you forget about it).
George
On Sunday, November 24, 2002, at 01:04 PM, Paul Johnson wrote:
On Sun, Nov 24, 2002 at 12:13:55PM -0500, Tanton
On Sun, Nov 24, 2002 at 12:13:55PM -0500, Tanton Gibbs wrote:
> So, the purpose of map is to change every element of an array in the same
> way and create a new array with those changed elements.
Quite. Whenever you need to create an list by performing an operation
on every element of another li
map takes a code block or an expression and evaluates it for each element in
a list
for example...
my @arr = (1,2,3,4,5);
my @arr2 = map {$_ + 3} @arr; # notice no comma
print "@arr2\n";
4 5 6 7 8
So, each element of @arr had 3 added to it.
Another example, using an expression would be
my