Again, correct me if I'm wrong -- what you'd like to do in the end is output a table roughly like the following:

Customer | Money spent -----------------+------------- Fred Flintstone | 1000 Barney Rubble | 2000 ... | ...

I'll assume from this point on that that's the case.

How to best go about this depends on how %myHash is structured, exactly. If it's a hash of hashes, holding (for each customer) a hash with several pieces of information, including the money they spent, proceed as in Re: Keys and Values from Hash to obtain a hash containing only, for each customer, the amount of money they spent. Your original post suggests that this is the case.

If it's already a hash of that form, you're done. Your reply at Re^2: Keys and Values from Hash suggests that this is the case instead.

Either way, once you've got the resulting hash, simply iterate over it and output HTML in some way to create your page:

foreach my $customer (keys %money_spent) { my $money_sent_by_this_customer = $money_spent{$customer}; # do something with $customer and $money_spent_by_this_customer }

That said, you may not even need to do any of this; you could equally well just do this, obviating the need for an intermediate hash entirely:

foreach my $customer (keys %myHash) { my $money_sent_by_this_customer = $myHash{$customer}->{"money"}; # do something with $customer and $money_spent_by_this_customer }

I hope this helps.

BTW, I'm getting the feeling that you're not so familiar/at ease with the concept of hashes as such yet. Be sure to read up on them -- see Associative array, Programming Perl p. 76-77 (page numbers for 3rd edition), perldata, perlfaq4: Data: Hashes (Associative Arrays), Not Exactly a Hash Tutorial, Perl Hash Howto, etc.

EDIT: re: your added important info, if you've only got two data points for each customer, money spent at 9am and money spent at 3pm, I'd recommend simply using two separate hashes, each constructed as above. That, or (again) don't use intermediate hashes at all, and just do this:

foreach my $customer (keys %myHash) { my $money_sent_by_this_customer_at_9am = $myHash{$customer}->{"mon +ey9am"}; my $money_sent_by_this_customer_at_3pm = $myHash{$customer}->{"mon +ey3pm"}; # do something with $customer, $money_spent_by_this_customer_at_9a +m and $money_spent_by_this_customer_at_3pm }

In reply to Re^5: Keys and Values from Hash by AppleFritter
in thread Keys and Values from Hash by David92

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.