in reply to Breaking output lines into N-element chunks

the mod in the conditional might mess up a maintainance programmer
...or maybe even the original programmer. :-)
You forgot to increment $v_count, so the conditional is always true. 0 always == 0.

How about a C-style loop?

for( my $i=0; $i < scalar(@vars); $i++ ){ unless( $i % $LIMIT ){ print "\ndirective: "; } print &munge_var($vars[$i]) , " "; }
HTH --
______________________________ s!!password!;y?sordid?binger?; y.paw.mrk.;;print chr 0x5b ;;; print;print chr(0x5b+0x2);;;;;

Replies are listed 'Best First'.
Re: Re: Breaking output lines into N-element chunks
by demerphq (Chancellor) on Apr 12, 2002 at 13:49 UTC
    How about a C-style loop?

    Whats wrong with a perl loop? Why use a loop form that is inclined toward error when you dont have to?

    for my $i (0..@vars-1){ }

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

        Whats wrong with a perl loop? Why use a loop form that is inclined toward error when you dont have to?
        for my $i (0..@vars-1){ }

      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

        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.

        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.