in reply to Delving the regexp underdark -- how to understand \G's behavior, or how to loop through a regular expression
This snippet pulls out the data beforehand and then processes it later:
This could be very memory intensive if you have a large $text however (since it will probably generate all the entries before it builds the array). On the other hand, you only have to use the RE once, which should at least somewhat speed things up (unless you're keen on precompiling your RE's anyway : )my @data = $text =~ /foo(.*?)bar/g; manipulate($_) foreach (@data);
HTH,
jynx
Update: You can also shorten this into:
But that might be a little overboard...manipulate($_) for (@{[$text =~ /foo(.*?)bar/g]});
|
|---|