Correct!
That is, provided that the passed-in-array does not itself contain references. For the purpose of this exercise, you may know that it won’t, but in the general case, it might, which is why a solution using wantarray may be preferable here, as explained above.
Note that “empty” here means the empty string, i.e. "", so to make the test more robust you could write:
my $type_of_arg = ref $_[0]; if ($type_of_arg eq "ARRAY") { # Handle an array reference } elsif ($type_of_arg eq "") { # Handle an array } else { die "Unexpected reference type '$type_of_arg': $!"; }
Hope that helps,
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
In reply to Re^8: How to combine these 2 subroutines in one?
by Athanasius
in thread How to combine these 2 subroutines in one?
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |