Perl Image Requests

← Back

Gravatar implementations with Perl are pretty straightforward, however you do need to include several external libraries. These are probably already installed on your machine, but if they're not, you'll have to download and install them.

Let's start by including those library functions that we'll utilize:

use URI::Escape qw(uri_escape);
use Digest::MD5 qw(md5_hex);

Next, assume the following variables are available to you:

my $email = 'someone@somewhere.com';
my $default = "https://www.example.com/default.jpg";
my $size = 40;

You can construct your gravatar url with the following Perl code:

my $grav_url = "https://www.gravatar.com/avatar/".md5_hex(lc $email)."?d=".uri_escape($default)."&s=".$size;

This only constructs the URL, so don't forget to place it in an img tag before printing it.

Perl Modules