-----Original Message----- From: Charles K. Clarkson [mailto:[EMAIL PROTECTED] Sent: Thursday, October 28, 2004 8:37 PM To: [EMAIL PROTECTED] Subject: RE: how summarise results from 2 hashes?
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 RE: inside are numbers! my $hasfromform1 = $hasfromform1->{$forma->{hasfromform1valuefromform}}; my $hasfromform2 = $hasfromform2->{$forma->{hasfromform2valuefromform}}; above send all numbers from form into my .pm : 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; RE: in fact foreach(keys %{$hasfromform1}){ : if($forma->{$_} eq $_){ : $hasfromform1 += $hasfromform2->{$_}; work when $hasfromform2 has 1 key only. How List::Util include into it? -GP -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>