我是 OO perl 的新手。我正在尝试编写一个简单的程序,但出现错误。
创建了一个包 Employee.pm 作为
package Employee;
sub new {
my $class = shift;
my $self = {};
bless $self, $class;
return $self;
}
sub get_names {
my $self = @_;
print " getting the names \n";
return $self;
}
sub set_names {
my ($self, $last_name) = @_;
$self->{last_name} = $last_name;
return $self->{$last_name};
}
1;
并创建了一个 .pl 文件为
use strict;
use warnings;
use Employee;
my $obj = new Employee("name" => "nitesh", "last_name" => "Goyal");
my $val = $obj->get_names();
print %$val;
my $setName = $obj->set_names("kumar");
print "$setName \n";
我收到错误
"Can't use string ("1") as a HASH ref while "strict refs" in use at class1.txt line 10."