[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Omaha.pm] Ow!! || bit me



So... 

Wouldn't this work?

$res->set_child_qty($cookie->{child_qty} || $q->param('child_qty') ||
0); 

Since it ignores the falses (0 and undef), it would fall through to the
last choice, which would be your default?

-----Original Message-----
From: omaha-pm-bounces@pm.org [mailto:omaha-pm-bounces@pm.org] On Behalf
Of Jay Hannah
Sent: Tuesday, September 20, 2005 10:15 AM
To: omaha-pm@pm.org
Subject: [Omaha.pm] Ow!! || bit me

Code:

  $res->set_child_qty    ($cookie->{child_qty} ||
$q->param('child_qty'));


When:

  $cookie->{child_qty}     is 0
       and
  $q->param('child_qty')   is undef


Then:

  I'm running   $res->set_child_qty(undef)

which is NOT what I wanted.


Doh! I need Perl 6's // operator! -grin-


New code:

  if (defined $cookie->{child_qty}) {
     $res->set_child_qty($cookie->{child_qty})
  } else {
     $res->set_child_qty($q->param('child_qty'))      
  }


Eww... Long and ugly. But it does do what I want and 0 is a valid value
for child_qty. 

$live && $learn++;

j

_______________________________________________
Omaha-pm mailing list
Omaha-pm@pm.org
http://mail.pm.org/mailman/listinfo/omaha-pm