<?xml version="1.0" encoding="windows-1252"?>
<node id="1010918" title="Re: A more concise way to map the contents of an array." created="2012-12-30 08:03:46" updated="2012-12-30 08:03:46">
<type id="11">
note</type>
<author id="708738">
LanX</author>
<data>
<field name="doctext">
you could use the [doc://perlop#Conditional-Operator|conditional operator] aka "ternary operator"  :&lt;P&gt;

&lt;c&gt;my @cell_contents = map { $_ ? 1 : 0 } @$array_ref[3..10];&lt;/c&gt;&lt;P&gt;

another idea is  to use doubled negation "&lt;c&gt;!!&lt;/c&gt;" and to map the empty string (false) to 0.&lt;P&gt;

&lt;c&gt;my @cell_contents = map { 0 + !!$_ } @$array_ref[3..10];&lt;/c&gt;&lt;P&gt;

but I don't think this conciseness justifies the loss of readability.¹&lt;P&gt;

&lt;!-- Node text goes above. Div tags should contain sig only --&gt;
&lt;div class="pmsig"&gt;&lt;div class="pmsig-708738"&gt;
&lt;p&gt;Cheers Rolf
&lt;/div&gt;&lt;/div&gt;&lt;P&gt;

¹) well if you really need 0 for false.</field>
<field name="root_node">
1010917</field>
<field name="parent_node">
1010917</field>
</data>
</node>
