I’m passing some arguments to a function, one of which might be undefined.
$a = ($config->function(param('a'),'int'));
my module contains a function which looks like this:
sub function{
my $self = $_[0];
my $t = $_[1];
my $type = $_[2];
print "$self,$t,$type<br/>";
}
I’ve tried with shift instead of the @_ syntax, but there’s no change.
The problem is that if $config->function is called with an undefined param('a') it prints like this:
MY_FUNC=HASH(0x206e9e0),name,
it seems that $t is being set to the value of what $type should be and the undef is being ignored completely.
The CGI
parammethod is correctly returning an empty list in the case of an error. This is standard behaviour for Perl subroutines and methods, which return a false value in the case of an erorr.As @mob says, an explicit
return undefis wrong precisely because it returns a one-element list in list context. This is a true value and implies success, which would break a lot of code if it was changedAll you need to do is change your code to extract the parameter separately
or if you’re really keen to put the call in the parameter list then you can write
or