[tpm] Stupid question time!

Uri Guttman uri at StemSystems.com
Fri Jan 29 18:59:20 PST 2010

>>>>> "FH" == Fulko Hew <fulko.hew at gmail.com> writes:

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

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

  FH> I would have thought

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

your code has the same bug at the other replier. you are not testing
$foo but $bar for truth. he want to set $bar only if $foo is true.

  FH> my $bar = $bar || $foo;

you should make that $bar =  $foo || $bar;

but that won't allow a my declare of $bar since $bar is referenced.


Uri Guttman  ------  uri at stemsystems.com  --------  http://www.sysarch.com --
-----  Perl Code Review , Architecture, Development, Training, Support ------
---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com ---------

More information about the toronto-pm mailing list