This is my first ever OOP programme and I would really like some feedback and advice on improving it. It has no real use, just an example I could apply my knowledge to.

Here are a few questions:

1) I'm struggling to understand the namespacing of $class and $self. If possible could someone explain when to use $class and when to use $self. 2) Is there a better way, other than to pass a subroutine condition as an arguement, to filter the return list. It works very nicely, giving me lots of freedom, but I can't remember seeing code like it before. 3) If I did e.g. "$$self[$index]{$key}" to access the objects data from inside the package, would this be acceptable. I'm not sure if the whole "looking inside the black box" applies to the method code alone, or code inside the package as well. 4) In the newPeople method, I do "bless $person;" to create an object inside an object, is this what an "instance" is.

Thank you very much in advance to anyone who is kind enough to take the time to look through my code.

I have done very little OO programming myself, but will try to answer your questions.

1) $class is the package, in this case it's profilePeople, and $self is the object that holds the data. The only time I use $class is when I'm creating the object i.e., inside the 'new' method.

2) I'm not 100% sure I understand your question. Write an accessor method to filter/return a person and another accessor method to return multiple people.

3) I would write that as $self[$index]->{$key} and would be inside the method. The last part of this question implies you want to use that outside of a method i.e., as a global package variable. The answer to that would be no.

4) An object is known as a '"class instance" and an object method is known as an "instance method". Does that answer your question?

Creating an object for every person as you are doing in the newPeople method is the wrong approach. Lets look at this from a different angle. Lets say that profilePeople is a mysql database and the newPeople sub inserts people into the database. You would not want to create a completely new duplicate table for each person you add. You would simply add them to the existing table.

So, in your case instead of using bless, you'd use push to add a new element/record. Your object should be a ref to an AoH.

On a side note, it would be better to extract the package code and put it in its own .pm file instead of including it inside your main script.

Thank you very very much for getting back to me. You have cleared a few things up.

Firstly, thank you for providing that book title. I currently use O'Reilly Intermediate Perl, which seems to breeze through OOP. I took a look at "Object Oriented Perl" on Amazon, and it seems to be what i'm looking for.

1) Cleared that up. That makes perfect sense.

2) I'm not 100% sure I understand what answer I was looking for. I'll have to put more thought into using multiple accessor methods which you suggested.

3) Since asking that question I was able to derive that I can do whatever I want with the object inside the package, but I must never access it directly outside the package. At first I didn't comprehend that an object is simply a reference.

4) That kind of answers my question. Again ill have to put more thought into it. As this is all new to me I need to take the time to read up on and define key terms which I haven't heard of before (class instance, instance method), just for further clarrification.

Ok I totally see where you are coming from, that an object within an object is unneccessary. I don't yet understand the alternative, as when it comes to accessing individual users, i.e.