Your biggest problem was:use strict; use warnings; {package Employee; sub spawn { my $invocant = shift; my $class = ref($invocant) || $invocant; + my $self = { empid => 200, name => "Joe", pay => 20, @_, }; return bless $self, $class; } sub empid { return $_[0]->{empid}}; sub name { my $self = shift; return $self-> {name}; } sub set_name { my $self = shift; $self-> {name} = shift; } sub pay { my $self = shift; return $self-> {pay}; } sub set_pay { my $self = shift; $self -> {pay} = shift; } sub PRINT{ my $self = shift; print $self->name," Earns ",$self->pay," dollars per hour. H +is/her Emp ID is: ",$self->empid, "\n"; } 1; # Indicates successful load when package is external } # End of package Employee my $wk1 = Employee->spawn(name=>"Joe", empid=>201, pay=>25); my $wk2 = Employee->spawn(name=>"Moe"); my $wk3 = Employee->spawn(name=>"Bob", empid=>202); for my $emp ($wk1,$wk2,$wk3){ $emp->PRINT(); } print "Got this far!", "\n"; $wk1->set_pay(70); $wk2->set_name("NewMoe"); for my $emp ($wk1,$wk2,$wk3){ $emp->PRINT(); }
return $self-> (name); # INCORRECT SYNTAX (looks like subroutine par +ameter) # vs. return $self-> {name}; # Braces indicate hash-element access
...Disinformation is not as good as datinformation. Don't document the program; program the document.
In reply to Re: "Can't locate object method" error
by NetWallah
in thread "Can't locate object method" error
by doctor T
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |