Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Accessing Subroutine Arguments

by Bobcat (Scribe)
on Apr 04, 2002 at 02:10 UTC ( #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.


Comment on Re: Accessing Subroutine Arguments
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (7)
As of 2014-09-22 06:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (182 votes), past polls