Skip to content

Instantly share code, notes, and snippets.

@kraih
Created October 12, 2011 11:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kraih/1280965 to your computer and use it in GitHub Desktop.
Save kraih/1280965 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use Mojo::Base -strict;
use Mojo::UserAgent;
# Lets start by fetching the current top Perl stories from Reddit
my $reddit =
Mojo::UserAgent->new->get('www.reddit.com/r/perl')->res->dom;
# And extract all titles from the HTML
my $titles =
$reddit->find('p.title > a.title')->map(sub { $_->text });
# How many do we got?
say 'Found ', $titles->size, ' stories.';
# Wonder how many actually contain the word "Perl"
say $titles->grep(sub {/perl/i})->size, ' contain the word Perl.';
# Top story
say 'Current top story is: ', $titles->first;
# Third story
say 'Third story is: ', $titles->[2];
# Random story that contains the word "Perl"
say 'Random Perl story: ', $titles->shuffle->first(sub {/perl/i});
# And now we go a little crazy :)
say 'Stories 2-5 in Base64:';
say $titles->slice(1 .. 4)->join('')->b64_encode;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment