Create a gist now

Instantly share code, notes, and snippets.

#!/usr/bin/env perl
use Mojo::Base -strict;
use Mojo::UserAgent;
# Lets start by fetching the current top Perl stories from Reddit
my $reddit =
# 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