Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^2: Are there corner cases I am missing

by GrandFather (Saint)
on Nov 14, 2011 at 20:33 UTC ( [id://938020]=note: print w/replies, xml ) Need Help??


in reply to Re: Are there corner cases I am missing
in thread Are there corner cases I am missing

If you are saying you are passing a huge list (more than 3) of position dependent parameters to a sub then you are buying yourself trouble right from the get go. Instead load up a hash with the parameters as you discover them then pass the hash into the sub. That gives you the equivalent of named parameters. Consider:

use 5.010; ... my %params; my @parts = split '.', $mystring; $params{cheese} = $parts[0]; $params{country} = $parts[1]; $params{state} = $parts[2]; $params{town} = $parts[3]; doSumpton(%params); ... sub doSumpton { my %params = @_; $params{cheese} //= '-- bad cheese --'; # Provide cheesy default print "Cheese: $params{cheese}\n"; }

Using a hash slice the assignments to the hash can be done as:

@params{qw(cheese country state town)} = @parts;
True laziness is hard work

Log In?
Username:
Password:

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

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

    No recent polls found