我正在构建我的第一个 Perl 构造函数,但我收到了这个错误。
Can't use string ("Managers::Toke::Interface") as a HASH ref while "strict refs" in use at
这是我的构造函数。
package Managers::Toke::Interface;
use strict;
use warnings;
use Core::ReturnValue;
use Data::Dumper;
## Toke stands for "The Online Kilobyte Extractor"
sub new {
my( $class, $username, $useruuid, $bytesSent, $bytesReceived, $bytePosition ) = @_ ;
my $self = {
'username'=> $username,
'useruuid'=> $useruuid,
'bytesSent'=> $bytesSent,
'bytesReceived' => $bytesReceived,
'bytePosition' => $bytePosition,
'date' => $date,
};
return bless $self, $class;
}
sub explain {
my $self = shift;
return sprintf "Hi, I'm %s", $self->{'username'};
}
这是调用它的程序:
my $return = Managers::Toke::Interface->new($username,
$uuid,
$receivedBytesToKB,
$sentBytesToKB,
$bytePosition) or die "$!";
$return = Managers::Toke::Interface->explain();
我希望答案不明显,在此先感谢。