Maxipoint Rep Office <[EMAIL PROTECTED]> top-posted:

: Additional: $hasfromform1 have as result only 1 key
: $hasfromform2 can have multiple keys (ever key by
: $hasfromform2 must be +
: with other $hasfromform2 key)

    A hash contains keys and values. Are you trying to
sum all the keys or all the values of $hasfromform2?

    Show us what is in each of the hashes you are using.

    $hasfromform1
    $forma
    $hasfromform2


: and at the end go: one key from $hasfromform1 + every
: key of $hasfromform2

   To get the sum of every value and every key in a
hash, use this.

use List::Util 'sum';

my %hash;

@hash{ 1 .. 4 } = 5 .. 9;

printf "Keys:   %s\n", sum keys %hash;
printf "Values: %s\n", sum values %hash;


: : how summarise results from 2 hashes?
: 
:     What do you mean by "summarise"?
:
: RE: I mean: every key of $hasfromform1 + every key of
: $hasfromform2 

    You said above that there is only 1 key in $hasfromform1.

use Data::Dumper 'Dumper';

my %hash1 = (
    1 => 2,
);

my %hash2 = (
    1 => 2,
    3 => 4,
);

my %sums;
foreach ( keys %hash1 ) {
    $sums{ $_ } = $hash1{ $_ } + $hash2{ $_ };
}

print Dumper \%sums;

__END__


HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to