in reply to Re: Re: Breaking output lines into N-element chunks
in thread Breaking output lines into N-element chunks

Oww oww oww! Make the hurting stop! Avoiding confusion between number-of-elements and last-valid-index is exactly why Perlish for loops are (usually) safer than C for loops. If you're going to be using $i as an array index, at least loop from 0 to $#vars instead of mucking about with length-1. IMO, your loop is more error-prone than a C-style loop, because eventually someone will forget the -1.

--
Good luck, tilly
:wq

Replies are listed 'Best First'.
Re: (FoxUni) Re(3): Breaking output lines into N-element chunks
by demerphq (Chancellor) on Apr 15, 2002 at 09:55 UTC
    at least loop from 0 to $#vars instead of mucking about with length-1

    Actually I used to do this. But I have started getting out of the habit as I understand $#array has been removed from Perl6.

    Do you really think its that confusing? @array is a one based number, and indexes are zero based. Seems pretty reasonable to me... And I have to say that definately _dont_ agree that its more error prone than a C-Style for loop.

    :-)

    Yves / DeMerphq
    ---
    Writing a good benchmark isnt as easy as it might look.

      But I have started getting out of the habit as I understand $#array has been removed from Perl6.

      Perl 6 isn't Perl 5.x, it's a new language that happens to be a lot like Perl 5. You will have to re-code things anyway. There will be a Perl 5 to 6 converter, so $#foo will be converted to @foo.end or @foo.last (I forgot which one it was), which is probably better than (@foo.length - 1).

      - Yes, I reinvent wheels.
      - Spam: Visit eurotraQ.
      

Re: (FoxUni) Re(3): Breaking output lines into N-element chunks
by demerphq (Chancellor) on Apr 15, 2002 at 09:54 UTC
    at least loop from 0 to $#vars instead of mucking about with length-1

    Actually I used to do this. But I have started getting out of the habit as I understand $#array has been removed from Perl6.

    Do you really think its that confusing? @array is a one based number, and indexes are zero based. Seems pretty reasonable to me...

    :-)

    Yves / DeMerphq
    ---
    Writing a good benchmark isnt as easy as it might look.