Yeah, my original post was pretty abstract, but that was mainly because I hadn't written any code yet. =]
I'll get down to some helpful details here.
I was coming at the same problem here from a different angle, and in a slightly simplified case. The general, long, drawn out form I'm looking at is this:
#I have some variables, and some ranges.
#really it's in a tied hash somewhere.
my %hash = { #pretend that this is my tied hash
a => "20",
b => "yes",
q => "1e-14"
};
my @range_a = (1..20);
my @range_b = ("yes", "no");
#each variable of interest has a foreach loop
# to go through the values in it's range
foreach my $a (@range_a){
$hash{a} = $a;
#other variables may be involved.
my $seed = srand($a + 42);
my $randomness = rand($seed);
#or a function
func_1(%hash);
foreach my $b (@range_b){
$hash{b} = $b;
my $foo = $b + $a;
#Then, at the innermost level, do something
#There could be any number (probably below 20)
# of these loops.
my $result = end_func(%hash);
}
}
I have already solved this with a recursive function and a hash of hashes containing the tied hash keys, the ranges they need to take on, and the statements that go in each layer. This was a little ugly, though, and scoping was interesting, to say the least. I was hoping to reduce the complexity for users dealing with this by objectifying it. My vision was something like this
#create objects in my class
my $a = param_class->new(\@range_a, $statements);
my $b = param_class->new(\@range_b, $statements);
$a->loop(
$b->loop(
&final_sub(%hash)
)
);
That's an ugly generalization, but hopefully that is more telling of where I was going with this rambling.
I'll be back tomorrow to talk more with you all about this.
~MB | [reply] [d/l] [select] |