Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Accessing Subroutine Arguments

by Bobcat (Scribe)
on Apr 04, 2002 at 02:10 UTC ( [id://156538]=note: print w/replies, xml ) Need Help??


in reply to Accessing Subroutine Arguments

I actually prefer to use the "named parameter" method. Not only does it lead to more readable code, but you can do neat things with defaults this way.
use strict; use Data::Dumper; sub foo { my %opt = ( text => 'Default Text' , style => 'Default Style' , bar => 'belch' ); %opt = ( %opt, @_ ); print Dumper \%opt; } foo(); # Options stay as specified above. foo( bar => 'yuk' ); # $opt{text} and $opt{style} stay the same, # $opt{bar} becomes 'yuk' instead of 'belch'.
I find this really handy for functions that can have a lot of obscure parameters that you only want to change once in a blue moon.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (4)
As of 2024-04-24 03:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found