in reply to Re: Idiomatic Array Index Search?
in thread Idiomatic Array Index Search?

Terrific write-up tachyon. Just one small (though crucial) quibble about the difference between '$#array' and 'scalar @array':
my @array = qw(a b c d e f); for (0..$#array) {print $_} # zero thru last index for (0..@array) {print $_} # zero thru size of array
prints: '0123450123456'

Replies are listed 'Best First'.
Re: Re: Re: Idiomatic Array Index Search?
by tachyon (Chancellor) on May 27, 2001 at 09:28 UTC

    Ah... good point. Perls auto vivification has obviously let me silently access one element past the end of the real array in that example. I normally use $#array but recently had to use @_ as $#_ was causing a syntax error (it was wickedly twisted code). I had thus far *failed* to note the difference.

    Thanks very much. I have added a correction to previous post with appropriate credit of course.

    On more pearl of wisdom duly filed

    tachyon