Is the correct syntax to check if a list is empty in perl:
if(@list == 0)
thanks
|
Team Leader
|
![]() |
| 12Dec2006,23:40 | #2 |
|
If that doesn't work, use this
Code: Perl
|
|
Go4Expert Member
|
|
| 3Mar2010,13:10 | #3 |
|
You can use the following way also.
Code:
my @arr ;
if ( @arr )
{
print "Array not empty\n";
}
else
{
print "Array empty\n";
}
By default this will be treated as scalar context |
|
Go4Expert Member
|
|
| 3Mar2010,13:14 | #4 |
|
Another way to test whether a list is empty is as follows
Code:
my @arr ;
if ( $#arr== -1 )
{
print "Array not empty\n";
}
else
{
print "Array empty\n";
}
If a list is not having any value means this will be -1. If a list is having only one element means this will be 0 and so on. |
|
Team Leader
|
![]() |
| 15Mar2010,17:37 | #5 |
|
Code: Perl
|

