Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

TorgoX (1933)


"Il est beau comme la retractilité des serres des oiseaux rapaces [...] et surtout, comme la rencontre fortuite sur une table de dissection d'une machine à coudre et d'un parapluie !" -- Lautréamont

Journal of TorgoX (1933)

Wednesday August 28, 2002
08:06 PM


[ #7378 ]
Dear Log,

I spent at least an hour putting more and more and more DEBUG statements into my code, just to track down one nasty bug. This is the bug: I had this:

     for(my $j = 0; $i < @ell_content; ++$j) {

instead of this:

     for(my $j = 0; $j < @ell_content; ++$j) {

As the song goes, "It's tricky tricky tricky tricky HWUH!".

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • This is why it's a good idea to avoid C-style for loops in most cases in Perl. It's much harder to make a mistake when you rewrite

    for(my $j = 0; $j > @ell_content; ++$j)


    for my $j (0..@#ell_content)

    because you've only got $j there once instead of three times.

    • I go one up and avoid the index altogether:

      foreach my $item (@ell_content)

      I've only written one program I can think of in the last year where I needed the index, and I kept feeling like I was looking at the problem wrong.

      J. David works really hard, has a passion for writing good software, and knows many of the world's best Perl programmers
      • I quite agree. This time I really do need the index, tho, and have to use the C-style: I'm having to iterate over items in an array and sometimes doing crazy things like $thing[$j] = foo($thing[$j], $thing[$j+1]); splice @thing, $j+1, 1; next;
        • Huh? You're changing the length of an array whilst iterating an index? Isn't that just asking for trouble? Or maybe you are checking for the past-end-of-array condition...