in reply to Infinite loop regex

Unless there is an advantage to getting the matches one at a time, I'd get them all at once by assigning to a list.

ListFoo

#!/usr/bin/perl $string = 'a=111a=222a=333'; @list = $string =~ m{(a=\d+)}g; for (@list) { print "$_\n"; }

Replies are listed 'Best First'.
Re: Re: Infinite loop regex
by tlhf (Scribe) on Aug 04, 2002 at 13:43 UTC
    Minor Nitpick:

    Why bother with the redundent @list?

    $string = 'a=111a=222a=333'; for ($string =~ m/(a=\d+)/g) { print "$_\n"; # any other code }

      For that matter, if you are grouping all the matches at once, why bother with the temporary string?

      for ($obj->method =~ /pat(keep)/g) { print $count++, " $_\n"; # etc. }

      --rjray