#完整版,綜合代碼介紹1,2
$text = <>; # Slurp up the first file given on the command line.
$text =~ s/&/&/g; # Make the basic HTML . . .
$text =~ s/</</g; # . . . characters &, <, and > . . .
$text =~ s/>/>/g; # . . . HTML safe.
$text =~ s/^\s+$/<p>/mg; # Separate paragraphs.
$HostnameRegex = qr/[-a-z0-9]+(\.[-a-z0-9]+)*\.(com|edu|info)/i;
# Turn email addresses into links . . .
$text =~ s{
\b
# Capture the address to $1 . . .
(
\w[-.\w]* # username
\@
$HostnameRegex # hostname
)
\b
}{<a href="mailto:$1">$1</a>}gix;
# Turn HTTP URLs into links . . .
$text =~ s{
\b
# Capture the URL to $1 . . .
(
http:// $HostnameRegex \b # hostname
(
/ [-a-z0-9_:\@&?=+,.!/~*'%\$]* # Optional path
(?<![.,?!]) # not allowed to end with [.,?!]
)?
)
}{<a href="$1">$1</a>}gix;
print $text;