Make sure it @_contains a reference to a single array.
sub mysub {
if ( @_ == 1 && ref( $_[0] ) eq 'ARRAY' ) {
} else {
}
}
The sentence ifchecks that only one argument is passed, and that the argument is an array reference using ref. To make sure the cases are the same:
sub mysub {
if ( @_ == 1 && ref( $_[0] ) eq 'ARRAY' ) {
@_ = @{ $_[0] };
}
}
source
share