evangraj has asked for the wisdom of the Perl Monks concerning the following question:
This problem: I am trying to create a hash or list of references of dates that have a hash table of sedols mapped to the total amount of shares traded. I need for every unquie day associated with it a hash table of unique sedols mapped to the the total amount traded for each. .... I am getting:
Type of arg 1 to keys must be hash (not hash elem) at line 556
this is the line:
what is wrong?????foreach $sedolelement (keys $tradedatehash{$tradedatemarker}) {
# ------ Build_tradedatehash_sedolandtotalsharesarray ----- sub Build_tradedatehash_sedolandtotalsharesarray($$$$) { #$j = shift; my $tradedate = shift; my $sedol = shift; my $shares = shift; $condition = ""; my $myfirstflag = shift; if ($myfirstflag eq "YES") { my $j = 0; } else { my $j = 1;} print "$tradedate $sedol $shares \n"; $count = 0; if ($j == 0) { $tradedatehash{$tradedate} = {$sedol => $shares}; foreach $tradedatemarker (%tradedatehash) { print "For the date: $tradedatemarker \n\tsedols \t total +shares\n\n"; foreach $sedolelement (keys $tradedatehash{$tradedatemarke +r}) { print "\t $sedolelement \t $_\n"; } print "\thave traded.\n"; } } else { #print "this is j $j\n"; foreach $tradedatemarker (${$tradedatehash{$tradedate}}) { if (exists $tradedatehash{%tradedate}) { print " yes yes yes $tradedatemarker\n!"; foreach $sedolelement (keys $tradedatehash{$tradedatem +arker}) { if (exists $sedol) { $tradedatehash{$trademarker}->{$sedol} += $sha +res; } else { $tradedatehash{$trademarker} = {$sedol => $sha +res}; }# } } else { $tradedatehash{$tradedate} = {$sedol => $shares}; } } foreach $tradedatemarker (${$tradedatehash{$tradedate}}) { print "For the date: $tradedatemarker \n\tsedols \t total +shares\n\n"; foreach $sedolelement (keys $tradedatehash{$tradedatemarke +r}) { print "\t $sedolelement \t $_\n"; } print "\thave traded.\n"; } } } # end sub Build_tradedatehash_sedolandtotalsharesarray
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Need help with hashes please!!!
by Masem (Monsignor) on Jan 27, 2002 at 05:12 UTC | |
|
Re: Need help with hashes please!!!
by jonjacobmoon (Pilgrim) on Jan 27, 2002 at 05:14 UTC |