aboutsummaryrefslogtreecommitdiff
path: root/challenge-023/mark-anderson/perl5/ch-3.pl
blob: 53603f7ab72eb706438c8243ff943f1424896364 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#!/usr/bin/env perl

use Modern::Perl '2018';
use Mojo::UserAgent;

my $ua = Mojo::UserAgent->new;

my $array = $ua->get("https://www.poemist.com/api/v1/randompoems")
            ->result->json;

foreach my $i (keys $array->@*) {
    printf "%-7s%s\n",   "URL:",   $array->[$i]->{url};
    printf "%-7s%s\n",   "Poet:",  $array->[$i]->{poet}->{name};
    printf "%-7s%s\n\n", "Title:", $array->[$i]->{title};
    say                            $array->[$i]->{content}, "\n";
}