<?xml version="1.0" encoding="windows-1252"?>
<node id="586664" title="Conditional Operator Confusion" created="2006-11-29 07:08:42" updated="2006-11-29 02:08:42">
<type id="115">
perlquestion</type>
<author id="66612">
Melly</author>
<data>
<field name="doctext">
&lt;p&gt;Hi Monkees,&lt;br /&gt;
&lt;p&gt;Why does the following code print 10 bars for the first section, yet behaves as I expected for the second?&lt;/p&gt;
&lt;code&gt;
#Huh? 10 bars, WTF?
for(1..10){
  $_&gt;5 ? $x='foo' : $x='bar';
  print "$_:$x\n";
}

# That's better - 5 foos and 5 bars
for(1..10){
  $x=($_&gt;5 ? 'foo' : 'bar');
  print "$_:$x\n";
}
&lt;/code&gt;

&lt;!-- Node text goes above. Div tags should contain sig only --&gt;
&lt;div class="pmsig"&gt;&lt;div class="pmsig-66612"&gt;
Tom Melly, tom@tomandlu.co.uk
&lt;/div&gt;&lt;/div&gt;</field>
</data>
</node>
