On Fri, Jan 29, 2010 at 8:38 PM, Fulko Hew <span dir="ltr">&lt;<a href="mailto:fulko.hew@gmail.com">fulko.hew@gmail.com</a>&gt;</span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
I would have thought <br><div class="gmail_quote"><div><br>$bar = $foo unless $bar;     ...might be more intuitive.?<br><br>... in retrospect. I guess it depends if yout think the glass is half full, or half empty?<br></div>
</div></blockquote><div><br>The most common example would be creating a hash which I&#39;m populating with values, and don&#39;t want a given key to exist() if the right hand side is undef.<br><br>my %foo;<br>$foo{bar} = $baz if $baz;<br>
<br>In this case...<br><br>$foo{bar} = $baz // undef;<br><br>...while interesting, isn&#39;t appropriate.<br><br>Another (related) example might be a dual use setter/getter, for the moment disregarding the &quot;: lvalue&quot; attribute.<br>
<br>sub foo {<br>    my ($self, $value) = @_;<br>    $self-&gt;{foo} = $value if $value;<br>  return $self-&gt;{foo};<br>}<br><br>Now you could this...<br><br>$obj-&gt;foo(&#39;bar&#39;); # set foo<br>$bar = $obj-&gt;foo; # get foo<br>
<br>Anyway, these are just simple examples off the top of my head. It can easily be more complex. I&#39;ve found myself thinking this periodically, so I figured worth asking. Maybe someone has a good reason why it&#39;s a dumb idea to worry about in the first place?<br>
 </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div class="gmail_quote"><div>but I don&#39;t think you want to put the my in front because ISTR that<br>
the variable would only poof into existence if the condition evaluated true.<br>so it would still be longer.<br></div></div></blockquote><div><br>You&#39;re absolute right about that. Noticed it right after I clicked send, but didn&#39;t want to create more noise by correcting myself.<br>
 </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div class="gmail_quote"><div>I don&#39;t think the &#39;if right-handed truthiness&#39; operator exists<br>
.. in a short hand form worth using :-|<br></div></div></blockquote><div><br>I wasn&#39;t sure, but then that only means it&#39;s time to avail myself of those more in the know. ;) Would be a cool/useful feature though, in my opinion.<br>
<br>--<br>Shaun Fryer<br></div></div><br>