-----Original Message-----
From: Jeff Pang [mailto:[EMAIL PROTECTED] 
Sent: Monday, October 09, 2006 7:48 AM
To: beginners
Subject: Re: Non-deprecated way to capture array length


>
>>I needed to find out the length of an array and did it by referencing 
>>the array in scalar context. However, "use warnings" indicated that
this 
>>is a deprecated feature.  Is there a non-deprecated way to do this 
>>(other than looping through the whole array until I run out of 
>>elements)? Thanks.
>>
>
>How do you write it? I can get it like:
>
>$ perl -Mstrict -Mwarnings -le 'my @arr=qw/aa bb cc/;print length(join
"",@arr)'  
>6
>

Sorry, if you mean the number of elements in an array,then it should be:

my $num = scalar @array;

--
Jeff Pang
NetEase AntiSpam Team
http://corp.netease.com

-- 
Perhaps I'm behind the times here, but what's wrong with:

my $num = $#array

??

That's how I always do it.

Kim Helliwell
LSI Logic Corporation
Work: 408 433 8475
Cell: 408 832 5365
[EMAIL PROTECTED]
 
Please Note: My email address will change to [EMAIL PROTECTED] on
Oct 14. The old 'lsil.com' email address will stop working after Jan 15,
2007. Please update your address book and distribution lists
accordingly. Thank you.

To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to