* Jeremy Mann <[EMAIL PROTECTED]> [2003-12-19T13:47:26] > Given this in $_ > <p>Most popular title searches:</p><ol><li><a > HREF="/title/tt0244365/">"Enterprise" (2001)</a></li>" > > why would this regex not put digits in $1 ? > > $data2 =~ /popular title searches:<\/p><ol><li><a > HREF=\"\/title\/tt(\d*)\/\">/
This code:
$data2 = '<p>Most popular title searches:</p><ol><li><a
HREF="/title/tt0244365/">"Enterprise" (2001)</a></li>';
$data2 =~ /popular title searches:<\/p><ol><li><a
HREF=\"\/title\/tt(\d*)\/\">/;
print $1;
prints '0244365'.
Notice that I put the string into $data2, not $_. A bare regex (/foo/)
would work on $_, but you're using the =~ operator to fit the regex to
$data2, so the value in $_ is irrelevant. Perhaps you wanted:
($data2) = ($_ =~ /r(ege)x/); # assign $1 to $data2
Also, keep in mind that while // is the most common delimiter for a
regex, it can lead to readability problems. If you're going to have a /
character in your regex, why not a different delimiter for the regex?
It'll save you from escaping the slashes. So:
$data2 =~ m!popular title searches:</p>!;
Also, you didn't need to escape the quotes in the regex, you could have:
$data2 =~ m!<a HREF="/title/tt(\d*)/">!;
I hope these pointers help.
--
rjbs
pgp00000.pgp
Description: PGP signature
