in reply to Re: one line regex eating CPU
in thread one line regex eating CPU

Thanks, that did fix it. But I swear I did this before where I did push(@array, $1) ... because I actually like that form better than push @array, ..

How would this method match $1 AND $2 then (assuming we had a second capture going on)?

Replies are listed 'Best First'.
Re^3: one line regex eating CPU
by GrandFather (Saint) on Jun 23, 2006 at 20:20 UTC

    Something like this may do what you want:

    use strict; use warnings; my @titles; my $source = <<TEXT; <title id='1'>www.perlmonks.org</title> <title id='2'>somewhere else</title> TEXT push @titles, $source =~ m/<title\s+id='(\d+)'>(.+?)<\/title>/igs; while (@titles) { my @pair = splice @titles, 0, 2; print "$pair[0]: $pair[1]\n"; }

    Prints:

    1: www.perlmonks.org 2: somewhere else

    DWIM is Perl's answer to Gödel