Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^2: Assigning default values to function arguments which may be “empty”

by flowdy (Scribe)
on Aug 18, 2016 at 10:35 UTC ( [id://1169986]=note: print w/replies, xml ) Need Help??


in reply to Re: Assigning default values to function arguments which may be “empty”
in thread Assigning default values to function arguments which may be “empty”

Esp. syntax #2 looks a little overcomplicated, why not:

sub f { length or $_ = "default value" for my $var = shift; do_something_with($var); }
But in my humble opinion I'd prefer for the sake of clarity:
sub f { my $var = shift; for ( $var ) { last if length; $_ = $DEFAULT; } ... }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2024-04-20 00:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found