appleb has asked for the wisdom of the Perl Monks concerning the following question:
perl myScript -i origSamples -p 1 -o 100
all lovely jubbly. Then I decide to improve it so that I can run it many times without having to ask it implicitly by turning the arguments into lists.
perl myScript -i origSamples,moreSamples -p 1,3 -o 100,200
It calls the main processing subroutine many times
processOne('origSamples',1,100) processOne('origSamples',1,200) processOne('origSamples',3,100) processOne('origSamples',3,200) processOne('moreSamples',1,100) ...
but in order to achieve this, there are now many foreach statements that run each argument in combination with each of the other arguments in the other lists. There is one of the following for each argument option, all nested:
My customer has already added more arguments, so I want to store the arguments in a data structure that will allow me to combine each argument from each list in turn. Then if I add another argument or change it into a list I shouldn't have to recode. Where do I start? Arrays, hashes, hashes of arrays? Something efficient, but allows easy parsing into a list of arguments to send to a subroutine.if (scalar(@incls) > 0) { foreach $inc (@incls) { $args{i} = $inc; processOneCheckP(); } } else { processOneCheckP(); }
Cheers in anticipation.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Storing multiple arguments in a data structure that allows for future expansion
by Moron (Curate) on May 02, 2007 at 08:57 UTC | |
Re: Storing multiple arguments in a data structure that allows for future expansion
by jbert (Priest) on May 02, 2007 at 09:07 UTC | |
Re: Storing multiple arguments in a data structure that allows for future expansion
by Herkum (Parson) on May 02, 2007 at 11:59 UTC | |
Re: Storing multiple arguments in a data structure that allows for future expansion
by dragonchild (Archbishop) on May 02, 2007 at 17:15 UTC | |
Re: Storing multiple arguments in a data structure that allows for future expansion
by Anonymous Monk on May 02, 2007 at 20:05 UTC | |
Re: Storing multiple arguments in a data structure that allows for future expansion
by appleb (Novice) on May 03, 2007 at 03:53 UTC |