in reply to Re: counter issues
in thread counter issues

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.

Replies are listed 'Best First'.
Re^3: counter issues
by Aristotle (Chancellor) on May 13, 2003 at 16:00 UTC
    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.