> Bryan R Harris wrote:
>> 
>> Can someone explain what:
>> 
>> $pi ||= 3;
>> 
>> ...means?  I just saw it in Programming Perl (pp 540), but it doesn't
>> explain it.  Thx!
> 
> || is the logical OR operator (see perldoc perlop) which says that if $pi is
> TRUE then keep the current value of $pi but if $pi is FALSE then assign 3 to
> $pi.
> 
> That could also be written as:
> 
> unless ( $pi ) {
>     $pi = 3;
>     }



One last question on this--

Take this (lame) example of an RSVP to an invitation:

**************************************
$_ = "Bill, 3";   # name, number of folks attending (optional, defaults to
1)
($name,$numfolks) = m/([^,]+),?\s*(\d*)/;
$numfolks ||= 1;
**************************************

This works fine unless Bill enters "Bill, 0" (trying to say that he's not
coming).  Is there another way to write that so it gets the zero?

I've run into this problem several times...  TIA.

- B

Reply via email to