Conceal Email Address with JavaScript

I wrote this perl script years ago when I needed to include my email address on a webpage, but also conceal it from spam bots and spiders.

#!/usr/bin/perl -w

# /usr/local/bin/esc-mailto.pl
# Conceal email address with javaScript.
# by Jean-Sebastien Morisset (https://surniaulula.com/)

use strict;

my ($email, $text) = @ARGV;
$text = $email if (!$text);

if ($email && $text) {
	my $mailto = "<a href=\"mailto:$email\" class=\"esc-mailto\">$text</a>";
	$mailto =~ s/(.)/sprintf("%%%x", ord($1))/ge;
	print "<script language=\"JavaScript\">document.write(unescape(\"$mailto\"))</script>\n";
} else {
	print "syntax: $0 {email_address} [optional_link_text]\n";
	exit 1;
}

exit 0;

Continue reading