<?xml version="1.0" encoding="windows-1252"?>
<node id="1008169" title="Re^3: Problems with map(function, array)" created="2012-12-10 16:36:38" updated="2012-12-10 16:36:38">
<type id="11">
note</type>
<author id="176576">
eyepopslikeamosquito</author>
<data>
<field name="doctext">
&lt;P&gt;
Your original code with strict and warnings:
&lt;CODE&gt;
use strict;
use warnings;
sub twice { 2 * $_[0] }
my @a = map twice, 1..3;
print "@a\n";
&lt;/CODE&gt;
gives the warning
&lt;I&gt;"Use of uninitialized value $_[0] in multiplication (*) at map1.pl line 3".&lt;/I&gt;
&lt;/P&gt;

&lt;P&gt;
This is how it should be written:
&lt;CODE&gt;
use strict;
use warnings;
sub twice { 2 * $_[0] }
my @a = map twice($_), 1..3;
print "@a\n";
&lt;/CODE&gt;
which produces &lt;CODE&gt;2 4 6&lt;/CODE&gt; as expected.
&lt;/P&gt;

&lt;P&gt;
BTW, Conway, in
&lt;a href="http://shop.oreilly.com/product/9780596001735.do"&gt;Perl Best Practices&lt;/a&gt;, chapter 8,
recommends always using the block
form of [doc://map], not the expression form that you are using.
The expression form might be faster than the block form
though
(if that matters, you should benchmark it).
&lt;/P&gt;</field>
<field name="root_node">
1008163</field>
<field name="parent_node">
1008166</field>
</data>
</node>
