in reply to "Can't locate object method" error

Multiple fixes and idiomatic optimizations:
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(); }
Your biggest problem was:
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.

Replies are listed 'Best First'.
Re^2: "Can't locate object method" error
by doctor T (Initiate) on Apr 18, 2017 at 19:34 UTC

    Thank you guys for the help. I can now move forward and attempt new and daring things. I might have figured out the problem with the print statement but adding that "package main" was a few days off... I will be back Dr t

        "Next time, please chose a meaningful title."

        Choose.