<br><br><div class="gmail_quote">On Fri, Jan 29, 2010 at 7:40 PM, Shaun Fryer <span dir="ltr"><<a href="mailto:sfryer@sourcery.ca">sfryer@sourcery.ca</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
I often find myself doing things like this...<br><br>my $bar = $foo if $foo;<br><br>...and I wish there were an assignment operator conditional on right-hand truthiness. maybe...<br clear="all"><br>my $bar ?= $foo; # as opposed to $bar ||= $foo;<br>
<br>Thoughts? Have I overlooked an existing operator? Is this just a bad idea</blockquote><div><br>I would have thought <br><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>
<br>but I don'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><br>I suppose the alternative is<br>
<br>my $bar = $bar || $foo;<br><br>(now you could safely put the 'my' on) but thats still a little redundant :-(<br><br>I don't think the 'if right-handed truthiness' operator exists<br>.. in a short hand form worth using :-|<br>
</div></div><br>