Quick perl question 2

J

jack

I don't want to pester, but i have just one more follow up to this script
I'm writing:

The files I'm pulling has bylines in them. If I do this:

($byline, $title) = $_ =~ /By\s?(.*)<br><br>([A-Za-z
]+)<br><br>.*$/;
#($firstgraph) = $_ =~ /<p>(.*)<br><br>([A-Za-z ]+)<br><br>.*$/;
print "By: $byline\n\n";
print "Title: $title\n";

Then it will print out the Byline and title. Bingo, no problem. But, If I do
this:

$_ =~ s/By.*<br><br>.*<br><br>/g;

It will erase everthing up UNTIL the last two <br> tags -- which eliminates
the whole story except the last paragraph! How do I tell to only go through
the first and second sets of <br> tags?
(FYI, i'm trying to remove the byline and title so I can do nifty things,
like print out the first paragraph on an index page and correctly format the
byline later.
 
D

dw

jack said:
I don't want to pester, but i have just one more follow up to this script
I'm writing:

The files I'm pulling has bylines in them. If I do this:

($byline, $title) = $_ =~ /By\s?(.*)<br><br>([A-Za-z
]+)<br><br>.*$/;
#($firstgraph) = $_ =~ /<p>(.*)<br><br>([A-Za-z ]+)<br><br>.*$/;
print "By: $byline\n\n";
print "Title: $title\n";

Then it will print out the Byline and title. Bingo, no problem. But, If I do
this:

$_ =~ s/By.*<br><br>.*<br><br>/g;

It will erase everthing up UNTIL the last two <br> tags -- which eliminates
the whole story except the last paragraph! How do I tell to only go through
the first and second sets of <br> tags?
(FYI, i'm trying to remove the byline and title so I can do nifty things,
like print out the first paragraph on an index page and correctly format the
byline later.

Tell the .* not to be greedy by adding a ?
$_ =~ s/By.*?<br><br>.*?<br><br>/g;

However, this reg exp is incomplete since you don't specify what the found
text should be replaced with....
And, I'm not quite sure why you have the /g on there either.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,527
Members
44,998
Latest member
MarissaEub

Latest Threads

Top