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?
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With