I have another related issue here:
Building a Hash of arrays from a hash of arrays based on a list?
A full explanation is here.

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:

foreach $sedolelement (keys $tradedatehash{$tradedatemarker}) {
what is wrong?????
# ------ 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

In reply to Need help with hashes please!!! by evangraj

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.