Created
April 3, 2015 18:33
-
-
Save cabrinha/890fdde62fd1978c3d12 to your computer and use it in GitHub Desktop.
sub => ud
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use Mojo::URL; | |
| use Mojo::UserAgent; | |
| my $term = 'wtf'; | |
| my $url = Mojo::URL->new('http://api.urbandictionary.com/v0/define')->query(term => $term); | |
| my $tx = Mojo::UserAgent->new->get($url); | |
| if ($tx->success) { | |
| my $results = $tx->res->json; | |
| my $definitions = $results->{list}; | |
| foreach my $definition (@$definitions) { | |
| print $definition->{definition}, "\n"; | |
| } | |
| } else { | |
| my $err = $tx->error; | |
| die "$err->{code} response: $err->{message}" if $err->{code}; | |
| die "Connection error: $err->{message}"; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment