Hi,
I have these three sets of parameters. And I want to run these
group of parameters automatically.
#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;
How can I construct the code with the params setting (they are fixed) as above and the "main" subroutine below:
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);
}
Such that in the end it simply gives:
$result = {
'ParamGroup1' => 6, # 1+2+3
'ParamGroup2' => 12, # 3+4+5
'ParamGroup3' => 3, # 1+1+1
};
And my last question is. Can we avoid using "main subroutine"?
Will it be a better approach?
Thanks so much beforehand.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.