Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

perlfunc:map

by gods
on Aug 24, 1999 at 22:42 UTC ( #293=perlfunc: print w/ replies, xml ) Need Help??

map

See the current Perl documentation for map.

Here is our local, out-dated (pre-5.6) version:


map - apply a change to a list to get back a new list with the changes



map BLOCK LIST

map EXPR,LIST



Evaluates the BLOCK or EXPR for each element of LIST (locally setting $_ to each element) and returns the list value composed of the results of each such evaluation. Evaluates BLOCK or EXPR in a list context, so each element of LIST may produce zero, one, or more elements in the returned value.

    @chars = map(chr, @nums);

translates a list of numbers to the corresponding characters. And

    %hash = map { getkey($_) => $_ } @array;

is just a funny way to write

    %hash = ();
    foreach $_ (@array) {
        $hash{getkey($_)} = $_;
    }

Note that, because $_ is a reference into the list value, it can be used to modify the elements of the array. While this is useful and supported, it can cause bizarre results if the LIST is not a named array. See also grep for an array composed of those items of the original list for which the BLOCK or EXPR evaluates to true.


Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (13)
As of 2014-08-22 16:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (160 votes), past polls