### 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;
In reply to Can't call method on an undefined value? by jashmenn
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |