Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

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

by Lady_Aleena (Chaplain)
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


Comment on Re^2: Why won't a hash in a hash work as a hash reference to create an object?
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://964158]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (8)
As of 2014-08-20 11:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (111 votes), past polls