doctor T has asked for the wisdom of the Perl Monks concerning the following question:
I have been trying to learn Perl...i was doing well then i tried to take a new step and things quit working. Now i have this code that i have been attempting to run on ideone.com. I know the problem starts on line 40ish (the first print statement)but i have not been able to figure out why the process crashes... It's a simple thing and looks very square because i am coming from a long C++ background. Any help that can get me off of this hump would be sooooo much appreciated.
package Employee; sub spawn { my $invocant = shift; my $class = ref($invocant) || $invocant; + my $self = { empid => 200, name => "Joe", pay => 20, @_, }; sub get_name { my $self = shift; return $self-> (name); } sub set_name { my $self = shift; $self -> (name) = shift; } sub get_pay { my $self = shift; return $self-> (pay); } sub set_pay { my $self = shift; $self -> (pay) = shift; } return bless $self, $class; } $wk1 = Employee->spawn(name=>"Joe", empid=>201, pay=>25); $wk2 = Employee->spawn(name=>"Moe"); $wk3 = Employee->spawn(name=>"Bob", empid=>202); print $wk1->name," Earns ",$wk1->pay," dollars per hour. His/her Emp I +D is: ",$wk1->empid; print $wk2->name," Earns ",$wk2->pay," dollars per hour. His/her Emp I +D is: ",$wk2->empid; print $wk3->name," Earns ",$wk3->pay," dollars per hour. His/her Emp I +D is: ",$wk3->empid; print "Got this far!"; $wk1->set_pay(70); $wk2->set_name("NewMoe"); print $wk1;#->name," Earns ",$wk1->pay," dollars per hour. His/her Emp + ID is: ",$wk1->empid; print $wk2;#->name," Earns ",$wk2->pay," dollars per hour. His/her Emp + ID is: ",$wk2->empid; print $wk3;#->name," Earns ",$wk3->pay," dollars per hour. His/her Emp + ID is: ",$wk3->empid;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: "Can't locate object method" error
by NetWallah (Canon) on Apr 18, 2017 at 19:22 UTC | |
by doctor T (Initiate) on Apr 18, 2017 at 19:34 UTC | |
by LanX (Saint) on Apr 18, 2017 at 21:39 UTC | |
by Anonymous Monk on Apr 19, 2017 at 16:09 UTC | |
|
Re: "Can't locate object method" error
by Anonymous Monk on Apr 18, 2017 at 18:59 UTC | |
|
Re: "Can't locate object method" error
by karlgoethebier (Abbot) on Apr 19, 2017 at 08:50 UTC |