Stories
Slash Boxes
Comments
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

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • ... looping through the index for all elements in an array using
    for my $i (0 .. $#array) {
        ...
    }
    Again, the code is written under the assumption that the first array element has index 0.
    • Eeek, so our loops that require indexes should look like this? for my $i ($[ .. $#array) { ... } Wow, I have a lot of almost working code :)
      • Worse yet, you should almost never use that index. Try to do

        foreach my $elem (@array)
        if at all possible. The only time I use an index is when I have two parallel arrays. Using this other idiom completely eliminates the index: you just access the things you want to get to directly.
        --
        J. David works really hard, has a passion for writing good software, and knows many of the world's best Perl programmers