Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

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?

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (2)
As of 2015-11-29 05:54 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (747 votes), past polls