Perl error: unable to change non-lvalue subroutine call in

I get the following error with my class: "It is not possible to change the call to the non-lvalue subroutine in the line file.do 26." The file.do file 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?

+4
source share
1 answer

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

 $bookdb->dbh(0); 
+11
source

Source: https://habr.com/ru/post/1399606/


All Articles