<?xml version="1.0" encoding="windows-1252"?>
<node id="293" title="perlfunc:map" created="1999-08-24 18:42:58" updated="2005-08-13 03:31:33">
<type id="119">
perlfunc</type>
<author id="114">
gods</author>
<data>
<field name="doctext">
</field>
<field name="name">

&lt;P&gt;
map - apply a change to a list to get back a new list with the changes

&lt;P&gt;
&lt;HR&gt;
</field>
<field name="synopsis">

&lt;P&gt;
map 
&lt;FONT SIZE=-1&gt;BLOCK&lt;/FONT&gt; 
&lt;FONT SIZE=-1&gt;LIST&lt;/FONT&gt;

&lt;P&gt;
map 
&lt;FONT SIZE=-1&gt;EXPR,LIST&lt;/FONT&gt;

&lt;P&gt;
&lt;HR&gt;
</field>
<field name="description">

&lt;P&gt;
Evaluates the 
&lt;FONT SIZE=-1&gt;BLOCK&lt;/FONT&gt; or 
&lt;FONT SIZE=-1&gt;EXPR&lt;/FONT&gt; for each element of 
&lt;FONT SIZE=-1&gt;LIST&lt;/FONT&gt; (locally setting
 &lt;CODE&gt;$_&lt;/CODE&gt; to each element) and returns the list value composed of the results of each such evaluation. Evaluates 
&lt;FONT SIZE=-1&gt;BLOCK&lt;/FONT&gt; or 
&lt;FONT SIZE=-1&gt;EXPR&lt;/FONT&gt; in a list context, so each element of 
&lt;FONT SIZE=-1&gt;LIST&lt;/FONT&gt; may produce zero, one, or more elements in the returned value.

&lt;P&gt;
&lt;PRE&gt;    @chars = map(chr, @nums);
&lt;/PRE&gt;
&lt;P&gt;
translates a list of numbers to the corresponding characters. And

&lt;P&gt;
&lt;PRE&gt;    %hash = map { getkey($_) =&amp;gt; $_ } @array;
&lt;/PRE&gt;
&lt;P&gt;
is just a funny way to write

&lt;P&gt;
&lt;PRE&gt;    %hash = ();
    foreach $_ (@array) {
        $hash{getkey($_)} = $_;
    }
&lt;/PRE&gt;
&lt;P&gt;
Note that, because &lt;CODE&gt;$_&lt;/CODE&gt; 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 
&lt;FONT SIZE=-1&gt;LIST&lt;/FONT&gt; is not a named array. See also
 [perlfunc:grep|grep] for an array composed of those items of the original list for which the 
&lt;FONT SIZE=-1&gt;BLOCK&lt;/FONT&gt; or 
&lt;FONT SIZE=-1&gt;EXPR&lt;/FONT&gt; evaluates to true.

&lt;HR&gt;
</field>
</data>
</node>
