Basically, I’m trying to call a package function using only variables/scalars but I can’t figure out why I’m getting “ERROR: Incorrect argument in parentheses”.
Here’s the sample pm:
package foo;
sub bar {
my $request = @_[0];
if ($request eq 'fubar') {
my $response = 'definitely';
return $response;
else {
my $response = 'definitely not';
return $response;
}
}
1;
And the sample pl
use strict;
use lib "/blah/blah/custom_modules";
use sample;
my $package = 'foo';
my $package_sub = 'bar';
my $package_sub_args = 'fubar';
my $response = $package->$package_sub("$package_args");
print "$response\n";
And then I get the error.
Using any variations of the following will work however:
my $response = foo::bar('fubar');
my $response = foo::bar($package_sub_args);
But I believe that I cannot use variables in the type of OO notation above and must use the -> notation.
Anyway, help very much appreciated.
CLARIFICATION – The issue I’m having is with not knowing the package, sub or arguments until runtime. I can make it work when the sub doesn’t require arguments. But I have several subs that do require arguments and that’s where I’m stumbling…
This is simpler:
Works with strict.