[tpm] Stupid question time!

Fulko Hew fulko.hew at gmail.com
Fri Jan 29 17:38:31 PST 2010


On Fri, Jan 29, 2010 at 7:40 PM, Shaun Fryer <sfryer at sourcery.ca> wrote:

> I often find myself doing things like this...
>
> my $bar = $foo if $foo;
>
> ...and I wish there were an assignment operator conditional on right-hand
> truthiness. maybe...
>
> my $bar ?= $foo; # as opposed to $bar ||= $foo;
>
> Thoughts? Have I overlooked an existing operator? Is this just a bad idea


I would have thought

$bar = $foo unless $bar;     ...might be more intuitive.?

... in retrospect. I guess it depends if yout think the glass is half full,
or half empty?

but I don't think you want to put the my in front because ISTR that
the variable would only poof into existence if the condition evaluated true.
so it would still be longer.

I suppose the alternative is

my $bar = $bar || $foo;

(now you could safely put the 'my' on) but thats still a little redundant
:-(

I don't think the 'if right-handed truthiness' operator exists
.. in a short hand form worth using :-|
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/toronto-pm/attachments/20100129/02b84d38/attachment.html>


More information about the toronto-pm mailing list