Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: To test empty array in perl

by nvivek (Vicar)
on Apr 27, 2010 at 04:19 UTC ( #837017=note: print w/ replies, xml ) Need Help??


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);


Comment on Re: To test empty array in perl
Download Code
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]);

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://837017]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (15)
As of 2015-07-07 14:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (89 votes), past polls