Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I get the following error with my class: "Can't modify non-lvalue subroutine call at file.do line 26." My file.do looks something like this:

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

And my BookController.pm looks like this:

#!/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;

Any suggestions?

like image 550
JohnnyAce Avatar asked Dec 21 '22 01:12

JohnnyAce


1 Answers

You're attempting to set the return value of the sub, hence the error. Judging by the actual method, I think you meant:

$bookdb->dbh(0);
like image 58
Ry- Avatar answered Jan 09 '23 02:01

Ry-