in reply to Philosophies of Objects

"To a guy with a hammer, everything looks like a nail."

If you are new to OOP, then it might be fun for you to give it a try and learn from your (almost inevitable) mistakes. But I'm not sure we can give you good advice without a little more information about the particular problem you are trying to solve. Maybe I'm lazy today, but I'm having trouble envisioning your problem.

Of course, chances are that someone has already written something that could be easily adaptable to your problem space -- again, you'll get better results if you give us more concrete detail.

Replies are listed 'Best First'.
Re^2: Philosophies of Objects
by GuidoFubini (Acolyte) on May 23, 2006 at 20:24 UTC
    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