Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

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

by tye (Cardinal)
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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (5)
As of 2015-07-06 02:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (69 votes), past polls