Is it possible to in some way indicate if an array in Perl is undefined or null?
I find myself coming across situations where I would like to be able to differentiate between an empty array and one that hasn't been populated yet (or failed to populate for some reason).
So for instance, with an array reference I can do this:
my $apples;
$apples = get_apples();
if(defined $apples){
if(scalar @$apples == 0){
# We successfully got the list of apples, but there were none
}
}
else{
# There was a problem getting the list of apples
}
My only complaint about this is that "my $apples" doesn't tell you that $apples is intended to be an array reference, so @apples would be more specific.
It doesn't look there is a way to do something with an array explicitly. Is that the case? Will another variable always be required to indicate if the array was successfully populated?
The following could never be tested for a successful return of apples, right? Or am I missing something neat?
my @apples;
(@apples) = get_apples();
I know that get_apples could both return a success and a list to populate the array with, but I'm curious if there is a way to indicate a null or undefined value with just an array.
getpwuidandcaller.get_apples()could either return an array reference orundef.