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


>-- 
>Perhaps I'm behind the times here, but what's wrong with:
>
>my $num = $#array
>
>??

[EMAIL PROTECTED] ~]$ perl -Mstrict -Mwarnings -le 'my @arr=qw/aa bb
cc/;print $#arr'      
2
[EMAIL PROTECTED] ~]$ perl -Mstrict -Mwarnings -le 'my @arr=qw/aa bb
cc/;print scalar @arr'
3

They are not the same.
The $#arr is the last element's index number,while 'scalar @arr' is all
the elements' total number.

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

-- 

Oops, you're right! Guess I'm still half asleep this morning.
But $#arr + 1 is surely another way to get the result sought.
That's the way I always do it, not realizing that scalar @arr
was even available, I guess. However, scalar @arr is computationally
more efficient, I bet, and only slightly longer to write. So it's
probably a better way.

I'm not exactly a Perl beginner, but looks like I learned something
already from this list. Pretty good, seeing I only signed up 3 days
ago....

Kim Helliwell
LSI Logic Corporation
Work: 408 433 8475
Cell: 408 832 5365
[EMAIL PROTECTED]


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