From perlsub
The Perl model for function call and return values is simple: all functions are passed as parameters one single flat list of scalars, and all functions likewise return to their caller one single flat list of scalars. Any arrays or hashes in these call and return lists will collapse, losing their identities--but you may always use pass-by-reference instead to avoid this.
So, you can use references and ref()
to check type of reference
sub know_var {
my $this_var = shift;
if (ref($this_var) eq "ARRAY") {
print "This variable is an array reference!";
}
elsif (ref($this_var) eq "HASH") {
print "This variable is an hash reference!";
}
elsif (ref($this_var) eq "SCALAR") {
print "This variable is an scalar reference!";
}
elsif (!ref($this_var)) {
print "This variable is plain scalar!";
}
}
know_var(\@array);
know_var(\%hash);
know_var(\$scalar);
know_var($scalar);