Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

pattern matching. anything wrong with doing this?

Status
Not open for further replies.

m4trix

Vendor
Jul 31, 2002
84
CA
Let's say I have the source code to a webpage contained as a string in a scalar, and all I want to do is print JUST the <body> tag (and everything contained within). I did it like this:

$source =~ s/(<body[^>]+>)/$1/;
print $1;

This works fine - but is there a more appropriate way to do it? It just somehow seems that the substitution function isn't designed for this, but I don't know a better way.
 
Use match, m//, instead:
Code:
if ( $source =~ /(<body[^>]+>)/ ) {
    print $1;
}
jaa
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top