Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Are there corner cases I am missing

by monk2b (Pilgrim)
on Nov 14, 2011 at 18:02 UTC ( [id://937997]=note: print w/replies, xml ) Need Help??


in reply to Are there corner cases I am missing

Sorry Guys, I can see my question and code was not clear at all. I did not copy and paste the actual code I thought I would try to boil it down to its most simple form. my string is not "major.minor.build.revision" My string would literally look like this
$mystring = "gouda.usa.texas.dallas";
I am using Config::Inifiles in fictitious dosumpton and validation would take there because if Section and Parameter are not in the config file then I will add default data or kill the job based on other parameters passed to dosumpton. dosumpton takes many more parameters than shown. I just wanted to know what corner cases the algorithm would miss. As a blue collar or more appropriately shadetree developer the algorithm is where I tend to have more short commings.

Replies are listed 'Best First'.
Re^2: Are there corner cases I am missing
by GrandFather (Saint) on Nov 14, 2011 at 20:33 UTC

    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
Re^2: Are there corner cases I am missing
by jethro (Monsignor) on Nov 15, 2011 at 11:37 UTC

    I can garantuee you that nobody here thought that the string was "major.minor.build.revision". Not because I can mind read but because your script is really not that complicated and none of the answers to your post seems to assume a fixed string.

    You might not be aware that in perl the following is true:

    @a=("one","two"); dosumption(@a); # is the same as @a a=("one","two",undef); dosumption(@a); # is the same as dosumption("one","two");

    And because of that the solutions offered to you are really equivalent to your script (with the exception of what happens to "" and "0" both of which result to false without being undef) but mich simpler and less error prone

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (6)
As of 2024-04-19 10:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found