in reply to Re^2: Initialization of arrays
in thread Initialization of arrays
For times when I access the last element of an array, I use @array[-1]; however, when I need to know the value of the last index, such as in a loop above, I have seen people recommend two approaches. Let's use the for snippet from the above -- it could be written in either of:
for my $y (0..@x-1) { } # or # for my $y (0..$#x) { }
Is there a practical difference?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: (digression) preferred syntax for index of last array element?
by ikegami (Patriarch) on Sep 22, 2005 at 14:39 UTC | |
by ambrus (Abbot) on Sep 23, 2005 at 16:24 UTC |