Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

how summarise results from 2 hashes?
how summarise results from 2 hashes?

it will not summarise key(s) from hasfromform2! I only have hasfromform1

foreach(keys %{$hasfromform1}){
if($forma->{$_} eq $_){
$hasfromform1 +=  $hasfromform2->{$_};
}


Report this thread to moderator Post Follow-up to this message
Old Post
Maxipoint Rep Office
10-28-04 08:57 PM


RE: how summarise results from 2 hashes?
Maxipoint Rep Office <maxipoint@st.htnet.hr> wrote:

: how summarise results from 2 hashes?

What do you mean by "summarise"?


: it will not summarise key(s) from hasfromform2! I only have
: hasfromform1
:
:   foreach(keys %{$hasfromform1}){
: 	if($forma->{$_} eq $_){
: 		$hasfromform1 +=  $hasfromform2->{$_};

You are attempting to increment a hash reference. That
doesn't make sense. Did you mean to use this?

$hasfromform1->{$_} +=  $hasfromform2->{$_};

: 	}

HTH,

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




Report this thread to moderator Post Follow-up to this message
Old Post
Charles K. Clarkson
10-28-04 08:57 PM


RE: how summarise results from 2 hashes?

: how summarise results from 2 hashes?

What do you mean by "summarise"?
RE: I mean: every key of $hasfromform1 + every key of $hasfromform2



: it will not summarise key(s) from hasfromform2! I only have
: hasfromform1
:
:   foreach(keys %{$hasfromform1}){
: 	if($forma->{$_} eq $_){
: 		$hasfromform1 +=  $hasfromform2->{$_};

You are attempting to increment a hash reference. That doesn't make
sense. Did you mean to use this?

$hasfromform1->{$_} +=  $hasfromform2->{$_};

: 	}

RE: what I must to do?
-GP



Report this thread to moderator Post Follow-up to this message
Old Post
Maxipoint Rep Office
10-28-04 08:57 PM


RE: how summarise results from 2 hashes?
Additional: $hasfromform1 have as result only 1 key
$hasfromform2 can have multiple keys (ever key by $hasfromform2 must be +
with other $hasfromform2 key)

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




: how summarise results from 2 hashes?

What do you mean by "summarise"?
RE: I mean: every key of $hasfromform1 + every key of $hasfromform2



: it will not summarise key(s) from hasfromform2! I only have
: hasfromform1
:
:   foreach(keys %{$hasfromform1}){
: 	if($forma->{$_} eq $_){
: 		$hasfromform1 +=  $hasfromform2->{$_};

You are attempting to increment a hash reference. That doesn't make
sense. Did you mean to use this?

$hasfromform1->{$_} +=  $hasfromform2->{$_};

: 	}

RE: what I must to do?
-GP



Report this thread to moderator Post Follow-up to this message
Old Post
Maxipoint Rep Office
10-28-04 08:57 PM


RE: how summarise results from 2 hashes?
Maxipoint Rep Office <maxipoint@st.htnet.hr> 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



Report this thread to moderator Post Follow-up to this message
Old Post
Charles K. Clarkson
10-28-04 08:57 PM


RE: how summarise results from 2 hashes?
in fact    foreach(keys %{$hasfromform1}){
: 	if($forma->{$_} eq $_){
: 		$hasfromform1 +=  $hasfromform2->{$_};

work when $hasfromform2 has 1 key only. But if I select more keys
calculation is not ok!


my $total = $hasfromform1 + $hasfromform2;


Report this thread to moderator Post Follow-up to this message
Old Post
Maxipoint Rep Office
10-28-04 08:57 PM


RE: how summarise results from 2 hashes?

-----Original Message-----
From: Charles K. Clarkson [mailto:cclarkson@htcomp.net]
Sent: Thursday, October 28, 2004 8:37 PM
To: beginners@perl.org
Subject: RE: how summarise results from 2 hashes?

Maxipoint Rep Office <maxipoint@st.htnet.hr> 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




Report this thread to moderator Post Follow-up to this message
Old Post
Maxipoint Rep Office
10-29-04 01:55 AM


RE: how summarise results from 2 hashes?
Maxipoint Rep Office <maxipoint@st.htnet.hr> wrote:

: Charles K. Clarkson [mailto:cclarkson@htcomp.net] wrote:
:
: : Maxipoint Rep Office <maxipoint@st.htnet.hr> 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}};

Thanks, but that doesn't tell me what is in there. Show us
the actual values in all three hashes. You can get the values
using the Dumper() function from the Data::Dumper module.

use Data::Dumper 'Dumper';

print Dumper( $hasfromform1, $forma, $hasfromform2 );


: above send all numbers from form into my .pm

I have no idea what that means.


: : : 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.

Show us a working example. Something we can run from our
own computer.


: How List::Util include into it?

I don't understand your question.

HTH,

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




Report this thread to moderator Post Follow-up to this message
Old Post
Charles K. Clarkson
10-30-04 01:55 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PERL Beginners archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 05:21 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.