Not exactly. If the array @arr is undefined, $#arr == -1, which actually equates to true (being a real, non-zero value). The real equivalent is if ($#arr >= 0).
Generally, if I want to check for the existance of an array containing values, I check for the existance of the first member: if ($arr[0]). However, even that isn't a perfect test (see examples below).
#!/usr/bin/perl
use strict;
use warnings;
my @asdf = ();
print "hi\n" if ($#asdf);
print "howdy\n" if (scalar @asdf);
print "hola\n" if ($asdf[0]);
print "---\n";
@asdf = ('a');
print "hi\n" if ($#asdf);
print "howdy\n" if (scalar @asdf);
print "hola\n" if ($asdf[0]);
print "---\n";
@asdf = ('','a');
print "hi\n" if ($#asdf);
print "howdy\n" if (scalar @asdf);
print "hola\n" if ($asdf[0]);
__END__
Output:
hi
---
howdy
hola
---
hi
howdy
| [reply] [d/l] [select] |