Yes you are right !!
Thanx
Dharmender Rai
--- "John W. Krahn" <[EMAIL PROTECTED]> wrote: >
Dharmender rai wrote:
> >
> > You can use defined() function by checking for the
> > first element.
>
> No, checking the first element of an array will tell
> you whether or not
> the first element of
Dharmender rai wrote:
>
> You can use defined() function by checking for the
> first element.
No, checking the first element of an array will tell you whether or not
the first element of the array is defined, it will not tell you if the
array is empty.
John
--
use Perl;
program
fulfillment
-
I just noticed this thread, so forgive me if someone has already mentioned
this, or if I'm missing the original point. I just saw some bad examples of
how to accomplish what the subject asks, and felt I should chime in.
The idiomatic method for checking if an array has elements is simply:
i
You can use defined() function by checking for the
first element.
#!/usr/bin perl
use strict;
use warnings;
my @arr=(); ## empty
my $ref=\@arr; ##
if(!defined ($ref->[0]) {
# do your work here
}
if (!define ($arr->[0]) {
# do your work
}
--- dan <[EMAIL PROTECTED]> wrote: > or
>
> if (!$arr
On Friday, October 4, 2002, at 11:21 AM, dan wrote:
> or
>
> if (!$array[0]) {
This tests for a "true" value in the first element of an array, not if
it's empty. This test will succeed for the list (undef, 1, 2, "More
Data"), which is definitely not empty.
> # it's empty
> }
>
> your cho
On Fri, 2002-10-04 at 10:21, [EMAIL PROTECTED] wrote:
> or
>
> if (!$array[0]) {
> # it's empty
> }
>
> your choice :)
>
> dan
not quite... try that on this array:
@array = qw(0 1 2 3 4 5 6);
jjv
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTE
or
if (!$array[0]) {
# it's empty
}
your choice :)
dan
"Nikola Janceski" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> if(not @array){
> # it's empty
> }
>
> > -Original Message-
> > From: Bryan Harris [mailto:[EMAIL PROTECTED]]
> > Sent: Friday,
Bryan Harris wrote:
>
> What's the easiest way to check whether an array is empty?
An array in a scalar context returns the number of elements in the
array.
if ( @array == 0 ) { # explicit test for zero elements
unless ( @array ) { # implicit test for zero elements
John
--
use Perl;
program
HANDLE_EMPTY() unless @array;
James Gray
On Friday, October 4, 2002, at 10:57 AM, Bryan Harris wrote:
>
>
> What's the easiest way to check whether an array is empty?
>
> I'm really feeling like a beginner today...
>
> - Bryan
>
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additio
if(not @array){
# it's empty
}
> -Original Message-
> From: Bryan Harris [mailto:[EMAIL PROTECTED]]
> Sent: Friday, October 04, 2002 11:58 AM
> To: Beginners Perl
> Subject: Check for empty array
>
>
>
>
> What's the easiest way to check whether an array is empty?
>
> I'm rea
10 matches
Mail list logo