I'm trying to put the result of some queries in one big ash.

The data looks like this:

NR------E-mail----------Comment---------Dates-------------Age--Action_ +date 12------Tom@info.com----blablabla-------AM0,PM0,AM1,PM1---32---10-10-2 +001 13------Frank@info.com--blablabla-------AM0,PM0-----------45---10-10-2 +001 14------Sand@info.com---blablabla-------AM1,PM1,PM2-------47---10-10-2 +001 14------Sand@info.com---blablabla-------AM1,PM1,PM2-------47---12-10-2 +001

I was thinking of one hash, key would be NR. Value should be again an hash where E-mail,comment,age,dates are again keys with there actual value. The value of Dates would be again a hash were the keys to it would be the Action Date (see two times NR 14)

so %Arec{NR->%{E-mail->value,comment->value,age->value,dates->%{date1->date1,date2->date2,....}}}

I've managed to code this in my fetch loop:

while (my $c = $st->fetchrow_hashref) { my %analyst_record; $a_record{$c->{ANA_ID}}{e_mail}=$c->{EMAIL}}; $a_record{$c->{ANA_ID}}{Dates}{comment}=$c->{DETAIL}; $a_record{$c->{ANA_ID}}{Dates}{$c->{ACTION_DATE}}{$c->{AM_0}}=$c->{AM_ +0}; $a_record{$c->{ANA_ID}}{Dates}{$c->{ACTION_DATE}}{$c->{AM_1}}=$c->{AM_ +1}; $a_record{$c->{ANA_ID}}{Dates}{$c->{ACTION_DATE}}{$c->{AM_2}}=$c->{AM_ +2}; $a_record{$c->{ANA_ID}}{Dates}{$c->{ACTION_DATE}}{$c->{AM_3}}=$c->{AM_ +3}; $a_record{$c->{ANA_ID}}{Dates}{$c->{ACTION_DATE}}{$c->{AM_4}}=$c->{AM_ +4};

1)Is this the correct way to build my hash?( hashes in hashes?)
2)I want to call a subroutine with as parameter a reference to my NR hash, meaning I don't want to give the funtion not the reference of the Big hash.

I want for every NR to call that subroutine with only one parameter, the reference of the hash of THAT NR.

My current (not working) code:

Show_analyst_row(\$analyst_record{$c->{ANA_ID}}); sub Show_analyst_row { my(%analyst_record) = %{@_}; print "$analyst_record{e_mail}\n"; }

This doesn't Work. How can you give the reference of an hash (this hash is actually the value in another hash) to a subroutine and how do you have to receive that reference-work with in the subroutine?

kind regards
Merlij

(Ps: many thanks to those who can help me, as you see at my question I'm a newbie into Perl. My only resource until now is "Programming Perl" from O'Reilly www.perl.com, do some of you have suggestions of other books should try? Thanks!)

2001-08-18 Edit by Corion : Added formatting, removed CODE tags around whole post.


In reply to References for subroutines to Hashes in Hashes :) by merlijn_u

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.