#!/usr/bin/perl
use strict;
use warnings;
use LWP::UserAgent;
my @tmp_array;
my $tmp;
my $ua = LWP::UserAgent->new();
# Fetch the XKCD fronpage...
my $response = $ua->get('http://xkcd.com');
if (not $response->is_success) {
print "Error: " . $response->status_line;
exit;
}
# Extract the lines containing title and perma-link from the HTML.
my ($title) = grep ( /
/, split /\n/, $response->decoded_content);
my ($permlink) = grep ( /Permanent link/, split /\n/, $response->decoded_content);
# Remove the title-tags from the ... title
$title =~ s/\s*<\/?title>//g;
# Remove HTML padding around perma-link
$permlink =~ s/<.*htt/htt/;
$permlink =~ s/\/<.*$/\//;
# Hey presto, title and link for the latest XKCD
print $title . " --> " . $permlink . "\n\n";