Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Values passed into a sub routine

by patcat88 (Deacon)
on Apr 20, 2011 at 00:29 UTC ( #900259=note: print w/ replies, xml ) Need Help??


in reply to Values passed into a sub routine

you can also have the first parameter control whether to interpret the rest of @_ as @_ or $_[0] as a hashref, for example,

sub func { my($param1, $param2, $param3) = @_; my $tempparam1; if(ref($param1) eq "HASH") { $tempparam1 = $param1->{'param1'}; $param2 = $param1->{'param2'}; $param3 = $param1->{'param3'}; $param1 = $tempparam1; } print "param1 is $param1 param2 is $param2 param3 is $param3 \n"; } func( 'one', 'two', 'three'); func( {param1 => 'one', param2 => 'two', param3 => 'three'});
I've seen the above in Perl. Offers users TIMTOWTDI.


Comment on Re: Values passed into a sub routine
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (13)
As of 2015-07-03 11:31 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 (51 votes), past polls