gpt4 book ai didi

Perl 错误 : Can't modify non-lvalue subroutine call at

转载 作者:行者123 更新时间:2023-12-04 22:34:56 26 4
gpt4 key购买 nike

我的类(class)出现以下错误:“无法修改 file.do 第 26 行的非左值子例程调用。”我的 file.do 看起来像这样:

line 2:    use BookController;
line 3: my $bookdb = BookController->new();
...
line 26: $bookdb->dbh = 0;

我的 BookController.pm 看起来像这样:
#!/usr/bin/perl

package BookController;
use strict;

sub new
{
my $this = shift;
my $class = ref($this) || $this;

my $self = {};
$self->{DBH} = undef;

bless $self, $class;

return ($self);
}

sub dbh
{
my $self = shift;
$self->{DBH} = shift if (@_);
return $self->{DBH};
}

1;

有什么建议么?

最佳答案

您正在尝试设置 sub 的返回值,因此出现错误。从实际的方法来看,我认为你的意思是:

$bookdb->dbh(0);

关于Perl 错误 : Can't modify non-lvalue subroutine call at,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9551819/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com