in reply to one line regex eating CPU
while puts the match in a scalar context and loops until killed by some external factor (every time you try the match succeeds unless it never does).
Try this to achieve what you are after:
use strict; use warnings; my @titles; my $source = "<title>www.perlmonks.org</title><title>somewhere else</t +itle>"; push @titles, $source =~ m/<title>(.+?)<\/title>/ig; print join("\n", @titles);
Prints:
www.perlmonks.org somewhere else
Note too that you need to non-greedy match (.+?), and as you know, this will very likely come unstuck used on HTML. :)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: one line regex eating CPU
by Anonymous Monk on Jun 23, 2006 at 20:11 UTC | |
by GrandFather (Saint) on Jun 23, 2006 at 20:20 UTC |