in reply to counter issues

You could use the foreach LIST form of the loop here for simplification. It will usually avoid mistakes such as the one you made, categorized as "off by one errors". Also, note that using the matches in list context here may save you from writing (and maintaining) a lot of banal code.
for my $i (0 .. $#array - 1) { ($x1, $y1) = ($array[$i] =~ m/\D(\D?\d+\D?\d*)\D(\D?\d+\D?\d*)\D/; ($x2, $y2) = ($array[$i + 1] =~ m/\D(\D?\d+\D?\d*)\D(\D?\d+\D?\d*) +\s*\D/); }

Makeshifts last the longest.

Replies are listed 'Best First'.
Re: Re: counter issues
by shemp (Deacon) on May 13, 2003 at 15:48 UTC
    One caveat with using foreach:
    What foreach actually does is first create an anonymous copy of the array you are foreach'ing over, then iterates over the copy of the list. So, if your list is rather large, foreach may result in memory usage issues.
      And for(;;) internally compiles to a while(){} continue{} construct which is pretty slow. If you have determined that the foreach loop is causing problems, you could resort to a regular while loop:
      my $i = 0; while($i++ < $#array) { ($x1, $y1) = ($array[$i] =~ m/\D(\D?\d+\D?\d*)\D(\D?\d+\D?\d*)\D/; ($x2, $y2) = ($array[$i + 1] =~ m/\D(\D?\d+\D?\d*)\D(\D?\d+\D?\d*) +\s*\D/); }
      But the foreach loop is much easier to read, so unless it was absolutely necessary I'd stick with that one.

      Makeshifts last the longest.