To expand a little on
TedPride's terse code segment, he is suggesting you open the page in your browser, save it as "surnames.html" in the same directory as a script with his code, then run the script
and feed "surnames.html" to it through STDIN (like perl script.pl < surnames.html).
Also note that the bold tags in the script are lower-case, so you probably want to make your match case-insensitive by adding the
/i modifier to your regex. Finally, if all you're interested in is the "Mac"s (as your original code fragment suggests), you might want to update the regular expression a little:
open ($handle, 'surnames.html');
while (<$handle>) {
$hash{$1} = () if m/^<\w+?><B>(Mac\w+?)<\/B>/i;
}
close ($handle);
print '"' . join ("\",\n\"", sort keys %hash) . '"';
[id://TedPride]'s code has taken advantage of the fact that all the surnames are between
<b> tags. The regular expression matches any text that starts with a general tag (
<\w+?>, like "<br>"), is then followed by a bold tag (
<B>) and a name starting with "Mac" and one or more following characters (
(Mac\w+?)). The parentheses "capture" the matched text to the special variable
$1.
Updated after [id://Anonymous Monk]'s post below.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.