On Sun, Jan 28, 2018 at 10:57:25PM +0000, Chas. Owens wrote:
> $#array is the index of the last element of @array, so it will be one less
> than scalar @array which is the number of elements in @array (since Perl
> arrays start with index 0). Therefore, to get the number of elements, you
> would need to add one to $#array, which makes scalar @array faster. To get
> the last index you would need to say @array - 1, which would make $#array
> faster.

But it doesn't matter, because this is not a bottleneck in your code.

So code for clarity.



> On Sun, Jan 28, 2018, 13:39 Peng Yu <pengyu...@gmail.com> wrote:
> 
> > Hi,
> >
> > For the following two expressions, are they of the same speed or one
> > of them is faster?
> >
> > `$#array` vs `scalar @array`

-- 
Paul Johnson - p...@pjcj.net
http://www.pjcj.net

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to