in reply to Getting a chunk of an HTML string?
$content =~ s#.*<h1>Random Movie Quote</h1>(.*)<P><form method=get act +ion="/Games/randomquote.html">.*#$1#s;
However, for extracting a string from some text, you are better off matching and just using the extracted string, rather then trying to substitute out everything else in one step:
if ($content =~ m#<h1>Random Movie Quote</h1>(.*)<P><form method=get a +ction="/Games/randomquote.html>#s) $content = $1; # we matched, replace $content with $1. # though it might be clearer to put it # in a different variable. } else { # we didn't match, complain. }
(Note that similarly you can check the return value of s/// to see if a substitution actually took place.)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Getting a chunk of an HTML string?
by tommyw (Hermit) on Oct 13, 2001 at 04:08 UTC |