On Fri, Jan 29, 2010 at 8:38 PM, Fulko Hew <span dir="ltr"><<a href="mailto:fulko.hew@gmail.com">fulko.hew@gmail.com</a>></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'm populating with values, and don'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't appropriate.<br><br>Another (related) example might be a dual use setter/getter, for the moment disregarding the ": lvalue" attribute.<br>
<br>sub foo {<br> my ($self, $value) = @_;<br> $self->{foo} = $value if $value;<br> return $self->{foo};<br>}<br><br>Now you could this...<br><br>$obj->foo('bar'); # set foo<br>$bar = $obj->foo; # get foo<br>
<br>Anyway, these are just simple examples off the top of my head. It can easily be more complex. I've found myself thinking this periodically, so I figured worth asking. Maybe someone has a good reason why it'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'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're absolute right about that. Noticed it right after I clicked send, but didn'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't think the 'if right-handed truthiness' operator exists<br>
.. in a short hand form worth using :-|<br></div></div></blockquote><div><br>I wasn't sure, but then that only means it'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>