Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re: RFC: Defined-Or for before Perl 5.10 (def(...))

by tye (Sage)
on Oct 29, 2010 at 19:12 UTC ( #868386=note: print w/ replies, xml ) Need Help??

in reply to RFC: Defined-Or for before Perl 5.10

See def -- Deal nicely with undefined values that I posted in 2000. But I'd actually do it differently:

sub def { my $var= \$_[0]; my $val; while( @_ && ! defined $val ) { $val= shift @_; } $$var= $val if ! defined wantarray; return $val; } # For example: my $size= def( $ENV{MAXSIZE}, -s $swapFile, -1 ); # Or void context causes $size to be modified def( my $size, $ENV{MAXSIZE}, -1 );

- tye        

Comment on Re: RFC: Defined-Or for before Perl 5.10 (def(...))
Download Code

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://868386]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2015-10-10 05:45 GMT
Find Nodes?
    Voting Booth?

    Does Humor Belong in Programming?

    Results (254 votes), past polls