I have a Perl controller class in which I do:
sub func1 {
my $f1 = Model::myModel->new();
my $param = "test";
$f1->func2($param);
}
Model class:
sub new {
my ($class, %arg) = @_;
my $self = bless {}, $class;
return $self;
}
sub func2 {
my ($self, $param) = shift(@_);
warn $param;
}
$param is blank. What is the mistake I am doing?
shiftonly shifts the first value off of@_.perldoc -f shiftwill tell you more about how shift works.You want:
You had it right innew(). Not sure what happened 😉Actually, FYI, your
new()will give the warning:If you call it like
$package->new( 'a' );You might want to trap that, something like:Or using whatever exception catching mechanism you use.