jashmenn has asked for the wisdom of the Perl Monks concerning the following question:
### test.pl ### use Employee my $person = Employee->new(); $person->name("bob"); $name = $person->name; print "hello, "; print $name; ### Employee.pm ### package Employee; use strict; sub new { my $invocant = shift; my $class = ref($invocant) || $invocant; my $self = { }; bless($self, $class); $self->{name} = "unknown"; return $self; } sub name { my $self = shift; if (@_) { $self->{name} = shift; } return $self->{name}; } 1;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Can't call method on an undefined value?
by dragonchild (Archbishop) on Apr 11, 2005 at 14:45 UTC | |
by ysth (Canon) on Apr 11, 2005 at 16:09 UTC | |
by dragonchild (Archbishop) on Apr 11, 2005 at 17:22 UTC | |
by ysth (Canon) on Apr 11, 2005 at 17:34 UTC | |
by dragonchild (Archbishop) on Apr 11, 2005 at 17:37 UTC | |
|
Re: Can't call method on an undefined value?
by borisz (Canon) on Apr 11, 2005 at 14:49 UTC |