Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Getting a chunk of an HTML string?

by wog (Curate)
on Oct 13, 2001 at 03:56 UTC ( [id://118601]=note: print w/replies, xml ) Need Help??


in reply to Getting a chunk of an HTML string?

Your problem is a result of . matching every character but newline, except if the /s option is used. See perlre for more details. Fixing this morphs your code into:

$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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://118601]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (2)
As of 2024-04-20 03:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found