Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
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);

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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://837017]
help
Chatterbox?
[choroba]: needed everywhere, available rarely
[LanX]: Question: starting a script from an icon in Windows, but after C-c the window closes ... what I want is to restart in the cmd.exe. Recommendations?
[Corion]: LanX: What do you mean by "restart in the cmd.exe" ?
[Corion]: Do you want to launch a script and keep the command prompt/console window open?
[Corion]: Do you want to wait for a key press before closing the window?
[LanX]: I want the command line in the history
[tye]: -Mouse
[Corion]: Option a) would mean launching cmd.exe /k c:\path\to\ batchfile- launching-perl- script.cmd. Option b) would be to add pause as the last line of said batch file.
[LanX]: First day after holidays ... and already stressed by the fact that colleagues changed stuff without communication ... apparently I'm the only one trying to fight entropy

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (13)
As of 2017-03-27 15:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (320 votes). Check out past polls.