in reply to one line regex eating CPU
Replace
push(@titles, $1) while $source =~ m/<title>(.+)<\/title>/i;
with
push(@titles, $1) while $source =~ m/<title>(.+?)<\/title>/ig;
to 1) avoid matching from the begining of $source every time, and 2) to avoid matching too much.
push(@titles, $source =~ m/<title>(.+?)<\/title>/i);
also works. It might even be faster. However, it uses more memory.
Update: Actually, there should be at most one title, so you want
push(@titles, $1) if $source =~ m/<title>(.+?)<\/title>/i;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: one line regex eating CPU
by shmem (Chancellor) on Jun 23, 2006 at 20:18 UTC | |
by ikegami (Patriarch) on Jun 23, 2006 at 20:19 UTC | |
by shmem (Chancellor) on Jun 23, 2006 at 20:26 UTC | |
by ikegami (Patriarch) on Jun 23, 2006 at 20:53 UTC |