John Doe wrote:
Am Montag, 18. April 2005 10.53 schrieb Vladimir D Belousov:I see, thank you!
Charles K. Clarkson wrote:
Aaron C. de Bruyn <mailto:[EMAIL PROTECTED]> wrote: : In the Perl documentation (perlintro) it says that you can find out : the number of elements in an array using the following syntax: : : print $myvar[$#mmyvar];
No. That prints the value of the last element of @myvar. The number
^^^
I beg your pardon, but why $myvar[$#mmyvar] is the first element of array?items in the array is the scalar evaluation of @myvar.
print scalar @myvar;
Read the line marked with ^^^^ above again :-)
perl -le ' use strict; use warnings; my @a=(1,2,3); print $a[$#a], "\n"; # here the same as $a[2]; ' # prints:
3
I mean 'but why $myvar[$#mmyvar] is the last element of array', not 'first' in my letter.
I thought that $#array is equal scalar(@array).
Sorry :)
For example:
@myvar = qw(a b c d e f g);
and as I can understend, $#myvar is 7, but the last element has index 6.
Yes, because the first array index is 0 and thus the number of elements one more than the last index.
perl -le' use strict; use warnings; my @a=(); my @b=(0); my @c=(0,1); print $#a, " / ", $#b, " / ", "\n"; ' # this prints:
-1 / 0 / 1
greetings joe
--HTH,
Charles K. Clarkson
Vladimir D Belousov
-- Vladimir D Belousov HiTech solutions for business http://businessreklama.ru