Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

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        

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 meditating upon the Monastery: (8)
As of 2016-10-24 18:23 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (309 votes). Check out past polls.