monkfan has asked for the wisdom of the Perl Monks concerning the following question:
How can I construct the code with the params setting (they are fixed) as above and the "main" subroutine below:#Parameters Group 1: my $x = 1; my $y = 2; my $z = 3; #Parameters Group 2: my $x = 3; my $y = 4; my $z = 5; #Parameters Group 3: my $x = 1; my $y = 1; my $z = 1;
Such that in the end it simply gives:sub main { my ($x,$y,$z) = @_; my %final_hash; # Something like this??? # I'm totally lost here # $final_hash{$paramgroup} = add_them($x,$y,$z); return %final_hash; } sub add_them { my ($x,$y,$z) = @_; return ($x+$y+$z); }
And my last question is. Can we avoid using "main subroutine"? Will it be a better approach?$result = { 'ParamGroup1' => 6, # 1+2+3 'ParamGroup2' => 12, # 3+4+5 'ParamGroup3' => 3, # 1+1+1 };
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Running Code with Multiple Sets of Parameters Automatically
by Zaxo (Archbishop) on Jul 25, 2005 at 03:10 UTC | |
|
Re: Running a Code with Multiple Sets of Parameters Automatically
by GrandFather (Saint) on Jul 25, 2005 at 03:11 UTC | |
by polettix (Vicar) on Jul 25, 2005 at 10:19 UTC | |
|
Re: Running a Code with Multiple Sets of Parameters Automatically
by spiritway (Vicar) on Jul 25, 2005 at 19:39 UTC |