Hello Perl Community, I want to build a complex hash. I want my hash structure to look like this: # %project = (<projectno1> => [<projdesc1>, # <hourtotal1>, # %days1 = (<day x> => [<hours>,<desc>], # <day y> => [<hours>, <desc>] # ) # ], # <projdesc2>, # <hourtotal2>, # %days2 = (<day x> => [<hours>,<desc>], # <day y> => [<hours>, <desc>] # ) # ] # )
I am having trouble building up and populating the individual %days hash. Here is what I have so far. use strict; my ( %project, $projectno, $desc, $day, %days, $i ); $projectno = "12345"; "$desc = "testing first project"; $project{$projectno} = [$desc, "0"]; # zero hours #later on, my code reads in some records such as # 3, 12, "painted a room" # 5, 6, "added a chair" # 14, 2, "made some calls" # for, say, project "12345" For my first test, I populated a smaller hash called %days. for ($i = 1; $i <=3; $i++) { ($day, $hour, $text) = split (',', <inline>); $days{$day} = ($hour, $text); } # # now that I have finished populating a smaller hash, I want to copy the hash on to the bigger hash. # push @{$project{$projectno}}, %days; Now I want to access the description field. So, if I know the project number and I know the day, how do I assign the description? So, $projectno = "12345"; $day = "5"; # # the next line fails to print out "added a chair" print ${$project{$projectno}[2]}{$day}; I get the error, Can't use string ("3") as a HASH ref while "strict refs" in use at c:\images\mactimesheet.pl line 40 1, <STDIN> line 1. I believe that the third entry for each project number key is the %days hash. I suspect I have a minor semantic error. I was hoping my print statement would have printed an array contaning (6, "added a chair"). The part, ${$project{$projectno}[2]}, I was thinking refers to the hash address; then the part, {$day}, is the key. Then again, maybe I am going at it all wrong with the push statement. Any help would be appreciated. Thank you Paul
_______________________________________________ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs