Perl Monk, Perl Meditation | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
You have used the $comment as a key in the hash and not the value to be assigned to the hash ... I will show an example at the bottom, probably taking a retrospective look can prove beneficial ... using the module Data::Dumper can allow you to view the data structure representation and understand or decide how to approach it since it makes that data structure stringified... The Data Structure Cookbook is fantastic, I hope you have consulted it and that you can revert to it over and over, it is so useful... I found Referencing in advanced data structures a very good source of clearing my confusion regarding many things...They seem difficult to understand but once you practiced them enough and you would find yourself starting to make sense of it all.. Also, Check the Tutorials section, for many related things have been graciously contributed by the beloved monks.... in the code example, notice the two lines:
In case your DATA looked like:
The name, the ID and then followed by more than one item to be associated with $name,$id, you would configure your split to break properly and then treat $hash{$name}{$id} as an anonymous array reference that would accept qw(some more info), using push or other array manipulation techniques... Iterating is done with respect to the type of reference and it's location within the structure, the function ref or the Data::Dumper output can be handy at this time
I hope this has been as concise and worthy for you to get to grabs, I haven't mentioned about iterating through @{$hash{$name}{$id}} for my confidence that you would figure it out. Let us know if you get any confusion...this is the entire code example Have an enjoyable Perl journey... Excellence is an Endeavor of Persistence. Chance Favors a Prepared Mind. In reply to Re: I don't understand hash references
by biohisham
|
|