in reply to To test empty array in perl

If you want to check whether the array is empty.You can do in the following ways.

print "Array isn't empty.Array Values:@array\n" if($array[0]); print "Array isn't empty.Array Values:@array\n" if($#array >= 0); print "Array isn't empty.Array Values:@array\n" if(@array);

Replies are listed 'Best First'.
Re^2: To test empty array in perl
by nagalenoj (Friar) on Apr 27, 2010 at 04:44 UTC
    print "Array isn't empty.Array Values:@array\n" if($array[0]);

    This won't tell you whether the array is empty.

    What happens when the first index of array has undef or 0.?

    # my @array = (0, undef, 1, 2, 3); my @array = (undef, undef, 1, 2, 3); print "Array isn't empty.Array Values:@array\n" if($array[0]);