-----Original Message-----
From: Bryan R Harris [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, June 07, 2006 4:43 PM
To: Beginners Perl
Subject: Re: defaults



> <snip>
>
> 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?

How about 

   $numfolks = 1 unless defined($numfolks);


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to