Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Re^2: Why won't a hash in a hash work as a hash reference to create an object?

by Lady_Aleena (Curate)
on Apr 09, 2012 at 16:56 UTC ( #964158=note: print w/replies, xml ) Need Help??

in reply to Re: Why won't a hash in a hash work as a hash reference to create an object?
in thread Why won't a hash in a hash work as a hash reference to create an object?

sundialsvc4, first thank you for the respect, courtesy, and politeness. You did not have to be any of those things, so I appreciate it. Perl is my first and only programming language, and I am learning programming concepts as I go. I had perltoot up in my browser as I was trying to write that object above, however the example in "Constructors and Instance Methods" did not show how a predefined data source, in my case an HoH, could be connected to an object. Even after reading perltoot, I made my best guess on how to reference a hash in a hash in an object even though my guess was wrong. Had perltoot started with package People; instead of package Person;, I may have gotten the hang of objects sooner.

perltoot starts with a table for one person we know nothing about (in this case Jason), instead of starting with a table for several people for whom we have already gathered data (not only Jason, but his peers Norbert, Rhys, and Phineas too). Had perltoot started with the following and created package people; first, it would have been more enlightening to me.

my $records = [ { name => "Jason", age => 23, peers => [ "Norbert", "Rhys", "Phineas"], }, { name => "Norbert", age => 24, peers => [ "Jason", "Phineas", "Michael"], }, { name => "Rhys", age => 22, peers => [ "Norbert", "Jason", "Robert"], }, { name => "Phineas", age => 23, peers => [ "Norbert", "Jason", "Alexandra"], }, ];

I could possibly take an example object which had an A(ref)oH and converted it to an HoH in my objects. I was having a hard time with perltoot starting in what I consider the end.

Have a cookie and a very nice day!
Lady Aleena

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://964158]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (4)
As of 2018-06-21 03:17 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (117 votes). Check out past polls.