mdarkar has asked for the wisdom of the Perl Monks concerning the following question:
Hi all, I'm relatively new to Perl and having a problem when trying to use objects. I have a very simple BankAccount object that I'm trying to write methods for, but I keep getting the following error:
Not a HASH reference at BankAccount.pm line 21
And my code is below, with line 21 being the return statement in the getName method
sub new { my $class = shift; my $self = {name => $_[0], accountNo => $_[1], balance => 0, }; bless($self, $class); return $self; } sub getName { my $self = shift; return $self->{"name"}; }
Sorry if I'm being really ignorant; it seems like it should be so simple, but I have no idea what I'm doing wrong or how to correct it.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: OOP Beginner
by GrandFather (Saint) on Apr 26, 2012 at 02:30 UTC | |
|
Re: OOP Beginner
by locked_user sundialsvc4 (Abbot) on Apr 26, 2012 at 11:45 UTC |