On Jan 2, 2004, at 10:18 AM, Jeff Westman wrote:
What is the proper way to test if an array is empty ?
Probably the easiest is:
if (@array) {
# not empty
}
else {
# empty
}
# or...
unless (@array) {
# empty
}
This works because an array in scalar context returns the numbe
What is the proper way to test if an array is empty ?
TIA
-JW
__
Do you Yahoo!?
Find out what made the Top Yahoo! Searches of 2003
http://search.yahoo.com/top2003
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
On Tue, 28 Oct 2003 11:53:44 -0700, Wiggins d Anconia wrote:
> or if you know the length of the array ahead of time:
>
> my @rows = ('','','');
I prefer the following instead:
my @rows = ('') x 3;
Easier to read...?
--
Tore Aursand <[EMAIL PROTECTED]>
--
To unsubscribe, e-mail: [EMAIL P
<[EMAIL PROTECTED]> wrote:
>
> How Do I initialize an empty array so thtat I don't get an unitiialized
> error?
>
> ...
> my @rows;
>
> I thought I could do something like @rows = new (); but it's not working.
You don't.
my @rows;
declares a
thanks. it works.
@rows=();
--
>
>
>> How Do I initialize an empty array so thtat I don't get an unitiialized
>> error?
>>
>> ...
>> my @rows;
>>
>> I thought I could do something like @rows = new (); but it's not
>> working.
&
>
>
> > How Do I initialize an empty array so thtat I don't get an unitiialized
> > error?
> >
> > ...
> > my @rows;
> >
> > I thought I could do something like @rows = new (); but it's not
working.
> >
>
> Drop the
> How Do I initialize an empty array so thtat I don't get an unitiialized
> error?
>
> ...
> my @rows;
>
> I thought I could do something like @rows = new (); but it's not working.
>
Drop the 'new':
my @rows = ();
http://danconia.org
--
T
How Do I initialize an empty array so thtat I don't get an unitiialized
error?
...
my @rows;
I thought I could do something like @rows = new (); but it's not working.
thanks
-
eMail solutions by
http://www.swanmail.com
--
To unsubscri
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
mpty
> > }
> >
> > > -Original Message-
> > > From: Bryan Harris [mailto:[EMAIL PROTECTED]]
> > > Sent: Friday, October 04, 2002 11:58 AM
> > > To: Beginners Perl
> > > Subject: Check for empty array
> > &g
gt; -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
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
: 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
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 c
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 additional commands, e-mail: [EMAIL PROTECTED]
19 matches
Mail list logo