The only thing that really sticks out like a sore thumb is that you've disregarded the class name which is passed to your constructor. Beyond that, if you're going to just use the package to create a hashref, you might as well do it via the constructor as well, with alternative defaults. Your first sub could/should/might (TMTOWTDI) look something like this:
sub new {
my ($class, $args) = @_;
bless { beverage => $args->{beverage} || "Pepsi",
entree => $args->{entree} || "soup",
dessert => $args->{dessert} || "ice cream",
}, $class;
}
At this point, it's simple to add another method to get/set/modify your object's individual attributes, or as a whole. You asked for alternative resources on OOP. Honestly, I can't think of anything more rewarding than Chapter 3 of Damian's book. If you haven't sat down and read it in it's entirety, you're performing a disservice to yourself. Quite honestly, it
is the bible... I had numerous lightbulbs "go off" before I was done with this chapter. :)
-fp
Update: Fixed the constructor. Thanks to
Zaxo for catching the error.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.