Perl: the Markov chain saw | |
PerlMonks |
Re: Storing multiple arguments in a data structure that allows for future expansionby jbert (Priest) |
on May 02, 2007 at 09:07 UTC ( [id://613140]=note: print w/replies, xml ) | Need Help?? |
I'm not sure this is the simplest way, but the problem suggested recursion to me. The code below demonstrates what I think you want to achieve. It's a 'first class functions' approach and uses the ability of a closure (anonymous subroutine) to capture information.
My starting point is where I think you are already - you have a hash whose keys are the options and whose values are array references containing the multiple-choice values. If you don't have that already, then simply go through the values of your options hash, replacing each value with [ split(/,/, $value) ] or similar. I then pass the multi-option hash and the function I was executed to the 'run_all_perms' function. This then plucks one key and list-of-values from the options hash. If we have more options to process, it recurses once for each value in the list, but we wrap the 'work' function in in a closure which installs the particular value in a hashref passed to the work function. If we don't have any more options to process, it can actually call the passed in work function, passing in the particular value. Here's the code:
In Section
Seekers of Perl Wisdom
|
|