in reply to How to substitute the elements in an array without changing the original array.
my @source = (1,2,3,4); my @dest = map { $_ * 2 } @source; print "@source\n"; print "@dest\n"; #Output: #1 2 3 4 #2 4 6 8
my @source = ('bob', 'joe'); my @dest = map { $_ eq 'bob' ? ucfirst($_) : $_ } @source; print "@source\n"; print "@dest\n"; #Output: #bob joe #Bob joe
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How to substitute the elements in an array without changing the original array. - map
by perladdict (Chaplain) on Dec 01, 2006 at 08:34 UTC |