in reply to $[ is under respected.

I hope your post is in jest. If you were tchrist, it would clearly be hilarious. :-) But since I don't know you and it's hard to tell in this low-bandwidth, high-latency medium ...

You're about 10 years too late. The perl community has used $[ and found it painful, ergo it is soon to be extirpated.

BTW, you've got the first idiom wrong. It is:

for (my $i = 0; $i < @array; $i++) { ... }

Replies are listed 'Best First'.
Re: $[ is under respected.
by jonadab (Parson) on Aug 03, 2005 at 11:32 UTC
    BTW, you've got the first idiom wrong. It is: for (my $i = 0; $i < @array; $i++) { ... }

    No, the correct idiom is usually

     for my $elt (@array) { ... }

    or, in those rare cases where you really do need an index into the array, it becomes

    for my $i (0 .. $#array) { ... }

    C-style three-clause for loops have been deemed unperlish, are deprecated, and have been removed from the core language in Perl6. If you really need the ability to manipulate the loop variable from within the loop, beyond what next and last provide, then use a while loop, but in general it's best to avoid that if possible. (Avoid using while loops in that way, I mean, not avoid using them at all.)

      C-style three-clause for loops have been deemed unperlish, are deprecated, and have been removed from the core language in Perl6.

      The C-style for loop hasn't been removed from perl6, it's just been renamed:

      loop my $i = 0; $i < $n; $i++ { ... }
      See S04

      And the C-style for loop has hardly been deemed "unperlish". If anything, it's unperlish for this particular purpose (iterating over an array index). It's certainly useful in other situations (though, in perl6, many of those situations are satisfied by other, newer language features)