#!/usr/bin/perl use strict; use warnings; use Data::Dumper; use LWP::Simple; use JSON; ### using api from http://mymovieapi.com/ # define url for get request # ghostbusters url my $url = "http://mymovieapi.com/?id=tt0087332&type=json&plot=simple&episode=1&lang=en-US&aka=simple&release=simple&business=0&tech=0"; # receive JSON into $response, via get call using LWP::Simple my $response = get $url; # die if we have problems making the GET request die 'Error making GET request -> $url' unless defined $response; # usual print line for troubleshooting #print Dumper($response); ### using JSON's decode_json we decode the JSON string into an array @data # my array @data gets the decoded JSON string my @data = decode_json($response); #print Dumper($data); # for each element in the now decoded array, make them accessible foreach (@data) { print $_->{title} . " was released in year -> " . $_->{year} . " , and it is rated " . $_->{rating}; } #### $VAR1 = { 'genres' => [ 'Comedy', 'Fantasy', 'Sci-Fi' ], 'plot_simple' => 'Three unemployed parapsychology professors set up sh op as a unique ghost removal service.', 'poster' => { 'imdb' => 'http://ia.media-imdb.com/images/M/MV5BNTUzMDU 3OTEyNV5BMl5BanBnXkFtZTYwOTk1MDE5._V1_SY317_CR2,0,214,317_.jpg', 'cover' => 'http://imdb-poster.b0.upaiyun.com/000/087/33 2.jpg!cover?_upt=a7275e191389164607' }, 'title' => 'Ghost Busters', 'year' => 1984, 'imdb_url' => 'http://www.imdb.com/title/tt0087332/', 'country' => [ 'USA' ], 'also_known_as' => [ 'Ghostbusters' ], 'writers' => [ 'Dan Aykroyd', 'Harold Ramis' ], 'language' => [ 'English' ], 'rating_count' => 167966, 'type' => 'M', 'directors' => [ 'Ivan Reitman' ], 'actors' => [ 'Bill Murray', 'Dan Aykroyd', 'Sigourney Weaver', 'Harold Ramis', 'Rick Moranis', 'Annie Potts', 'William Atherton', 'Ernie Hudson', 'David Margulies', 'Steven Tash', 'Jennifer Runyon', 'Slavitza Jovan', 'Michael Ensign', 'Alice Drummond', 'Jordan Charney' ], 'imdb_id' => 'tt0087332', 'runtime' => [ '105 min' ], 'filming_locations' => 'Greystone Park & Mansion - 905 Loma Vista Drive, Beverly Hills, California, USA', 'rating' => '7.8', 'release_date' => 19841202 };