diff options
| -rw-r--r-- | challenge-023/yet-ebreo/perl5/ch-3.pl | 28 | ||||
| -rw-r--r-- | challenge-023/yet-ebreo/perl6/ch-1.p6 | 2 | ||||
| -rw-r--r-- | challenge-023/yet-ebreo/perl6/ch-2.p6 | 2 |
3 files changed, 30 insertions, 2 deletions
diff --git a/challenge-023/yet-ebreo/perl5/ch-3.pl b/challenge-023/yet-ebreo/perl5/ch-3.pl new file mode 100644 index 0000000000..7d4bd97110 --- /dev/null +++ b/challenge-023/yet-ebreo/perl5/ch-3.pl @@ -0,0 +1,28 @@ +# Write a script to use Random Poems API. This is the easiset API, +# I have come across so far. You don’t need API key for this. +# They have only route to work with (GET). +# The API task is optional but we would love to see your solution. + +use strict; +use warnings; +use 5.010; + +use LWP::Simple qw(get); +use JSON; +binmode STDOUT, ":encoding(UTF-8)"; + +my $api_content = get "https://www.poemist.com/api/v1/randompoems"; +my @data; +push @data, @{$_} for JSON->new->utf8->decode($api_content); + +#Printing the info of the first poem +say "$data[0]{title} - $data[0]{poet}{name} - $data[0]{url}\n"; + +#Accessing all(5) poems +# for (@data) { +# say "$_->{title} - $_->{poet}{name} - $_->{url}"; +# } + +#Printing the content of the first poem +say "$data[0]{content}"; + diff --git a/challenge-023/yet-ebreo/perl6/ch-1.p6 b/challenge-023/yet-ebreo/perl6/ch-1.p6 index bc69ef39d1..2bfc4c59df 100644 --- a/challenge-023/yet-ebreo/perl6/ch-1.p6 +++ b/challenge-023/yet-ebreo/perl6/ch-1.p6 @@ -10,7 +10,7 @@ my ($n, @list) = @*ARGS; -die "Usage: ch-1.pl <n> <list>\n\tn\tmust be less than the number of elements in list\n\tlist\tvalues are space separated\n" if !@*ARGS; +die "Usage: ch-1.p6 <n> <list>\n\tn\tmust be less than the number of elements in list\n\tlist\tvalues are space separated\n" if !@*ARGS; die "n($n) must be less than the number("~@list.end+1~") of elements in list\n" if $n> @list.end; diff --git a/challenge-023/yet-ebreo/perl6/ch-2.p6 b/challenge-023/yet-ebreo/perl6/ch-2.p6 index f3996115cc..07c92eaf53 100644 --- a/challenge-023/yet-ebreo/perl6/ch-2.p6 +++ b/challenge-023/yet-ebreo/perl6/ch-2.p6 @@ -6,7 +6,7 @@ my $n = @*ARGS[0]; my $m = $n; -die "Usage: ch-2.pl <n> \n\tn is a postive number\n" if !@*ARGS; +die "Usage: ch-2.p6 <n> \n\tn is a postive number\n" if !@*ARGS; die "n must be a postive number\n" if $n < 1; #Backticks solution using factor, works both on windows and linux :D |
