On Wed, 20 Apr 2005, Keith Worthington wrote:

> Having written the following code I am now troubled by v_feet_str or 
> v_inch_str being undefined.  If there is no match can I return a 
> default value?  In my case if there is no dimension then I want to 
> move ahead using a zero in that position.

The usual idom for this is something like

    $foo = defined $foo ? $foo : 0;

Or maybe

    $foo ||= 0;

Or maybe simply

    $foo += 0;

I think I like the last one best. It's short, clear, and should do the 
right thing for you.

(Skipping ahead a bit, Perl6 , if I remember right, is going to have the 
'//' operator that tries to solve this sort of problem, allowing you to 
set a value for a variable if & only if it wasn't already defined. But 
it'll be a little while before this is available, though you can start 
playing around with things like this using the Perl6::* CPAN modules.)



-- 
Chris Devers

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