Always turn on warnings (<samp>perl -w</samp> or <samp>use warnings</samp> in newer Perls); for that matter, use strict unless you have good reason not to. In your case, -w would have caught the bug in your constructor:
doesn't use $class, instead preferring to shift some other element off of @_ to use as the class name. Additionally, you're always blessing and returning the same object (needlessly stored in a global variable), which is probably not what you wanted to do. In your case, you're passing undef to bless; you want to saysub new { my $class = shift; return bless($Person::list,shift); }
Continuing down your code, your methods aren't reading the object they should be working on. You want to say e.g.sub new { my $class = shift; return bless({},$class); }
Do this, and you should be able to say e.g.sub name { my $self = shift; $self->{NAME} = shift; }
my $person = new Person; $person->name('Me');
I'm curious, though, why you say ``the code in "Perl Cookbook" didn't work''. Could you please point us to what isn't working there?
In reply to Re: Classes Are Killing Me
by ariels
in thread Classes Are Killing Me
by straywalrus
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |