Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Trying to understand exactly what you mean by "more arguments".

Are you saying that you currently have arguments -i, -p, and -o, and your customer wants to add arguments -x, -y, and -z?

Or, are you saying you currently handle two arguments for each parameter, and your customer wants to use 5 for each parameter?

If you're talking about the former, I'd imagine you'd have to make some mods in your program to do that anyway. Before the processOne subroutine only is taking three paramters. Now, you'd have to not only pass in five parameters, but modify the code to actually use them. If you are referring to the same three parameters, but more values for them. You could do something like this:

my (@opt_i_list, @opt_o_list, @opt_p_list); # # ####Put options into Arrays # if ($opt_i) { @opt_i_list = split(",", $opt_i); } else { #No $opt_i parameter: Use default $opt_i_list[0] = $DEFAULT_OPT_I_VALUE; } if ($opt_o) { @opt_o_list = split(",", $opt_o); } else { $opt_o_list[0] = $DEFAULT_OPT_O_VALUE; } if ($opt_p) { @opt_p_list = split(",", $opt_p); } else { $opt_p_list[0] = $DEFAULT_OPT_P_VALUE; } # # ####Now run processOne for each arrangement of parameters # foreach my $opt_i_value (@opt_i_list) { foreach my $opt_o_value (@opt_o_list) { foreach my $opt_p_value (@opt_p_list { processOne('$opt_i_value',$opt_p_value,$opt_o_value) } } }
That will process all values of all the options against each other. So, if you have two options for each, the processOne subroutine will execute eight times. If there are 3 of each parameter, the processOne subroutine will execute 27 times.

If you add a parameter -x, you'd have to modify your processOne subroutine anyway. Adding another foreach loop in that structure would probably be relatively simple compared to the other coding changes you'd have to make. Is it efficient? Well, the number of times a loop has to process quickly grows with each additional value. That's not exactly efficient, but that's what you said you wanted.

In reply to Re: Storing multiple arguments in a data structure that allows for future expansion by Anonymous Monk
in thread Storing multiple arguments in a data structure that allows for future expansion by appleb

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2021-09-27 09:54 GMT
Find Nodes?
    Voting Booth?

    No recent polls found