The problem of sorting a file full of nothing but HTML mailto: links came across my desk, and armed with Perl I naturally solved it a few minutes (a miracle for me, this stuff is finally starting to stick). Then I noticed that not all of the links in the file actually contained mailto: even if they were linking to email addresses. So now I'm stuck trying to change my regex to match either the entire word "mailto:" or nothing at all. My best guess is commented below. Can anyone offer me advice? (And yes, I have read
Death to Dot Star! even if I don't fully comprehend it yet.)
#!/usr/bin/perl -w
use strict;
my %names;
while ( <> ) {
s/\s+/ /ig;
/<a href="(.*)">(.*)<\/a><br>/;
# /<a href="(mailto:)??(.*)">(.*)<\/a><br>/;
$names{"$2($1)"} = $1;
}
open OUT, ">sortboater.txt" or die "Cannot open file: $!";
for ( sort keys %names ) {
/^(.*)\(.*\)$/;
print OUT qq(<a href="mailto:$names{$_}">$1</a><br />\n);
}
close OUT or die "Cannot close file: $!";
-- More than perfect! Let us engage the Concord!
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.