in reply to Re: Answer: How do I find the index of the last element in an array?
in thread How do I find the index of the last element in an array?

I don't know what he means by: "$#foo + 1 isn't necessarily equal to @foo"(Some Perl array nuance I am not familiar with)

$[ = 5; my @foo = qw(a b c); printf "Number of elements: %d\n", scalar @foo; printf "Last index: %d\n", $#foo; printf "*Number of elements: %d\n", $#foo + 1; printf "*Last index: %d\n", scalar @foo - 1;
Number of elements: 3 Last index: 7 *Number of elements: 8 *Last index: 2
One should of course NEVER set $[, but that is besides the point.

Juerd # { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }

Replies are listed 'Best First'.
Re: Re: Re: Answer: How do I find the index of the last element in an array?
by pzbagel (Chaplain) on Jun 02, 2003 at 15:59 UTC

    Of course! Thanks for that answer Juerd! I'm willing to bet that "One should of course NEVER set $[" is exactly what the Camel book said too when I read about it so long ago.

    Thanks for the refresher.