merlijn_u has asked for the wisdom of the Perl Monks concerning the following question:
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.
|
|---|