By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,225 Members | 2,223 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,225 IT Pros & Developers. It's quick & easy.

Quick perl question 2

P: n/a
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.
Jul 19 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
dw

"jack" <ja**@raxo.net> wrote in message news:BB6E997A.373%ja**@raxo.net...
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.


Jul 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.