I have two nested packages that I am calling via fast_cgi. From the first Package I am invoking a method from the second like so:
$MyScalar = "A Value";
MyPackage::Inner->InvokeMe($MyScalar);
From my other package, I’m unwinding the parameters like this:
sub ZonesByCustomer($)
{
my $MyParameter = @_[0];
print $MyParameter;
}
What I’d expect is to have A Value get printed out, however what is actually getting printed out is MyPackage::Inner. A Value is actually being stored in @_[1].
This seems confusing. Why is the package name getting returned as a parameter?
This is abstracted from my code. I can provide a slightly more complicated version if I am missing something here that is essential.
Perl doesn’t have a “this” variable (implied or otherwise) like many other languages, yet the method needs that information. Instead, Perl provides the class (static method call) or object (instance method call) as the first argument of the method. The result of evaluating the argument list follows.
Example of static method requiring class name:
Example of instance method requiring object:
Note:
@_[0]and@_[1]should be$_[0]and$_[1].Note: Prototypes are generally bad, and ignored during method calls. Get rid of it.