in reply to File::Fetch fetch to scalar

It's not a hash ref, it's a JSON. JSON::PP is core, so it should be installed:
use JSON::PP; my $uri = decode_json($response)->{results}[0]{uri};

map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

Replies are listed 'Best First'.
Re^2: File::Fetch fetch to scalar
by vinoth.ree (Monsignor) on Jul 03, 2021 at 06:33 UTC
    Hi choroba

    Thanks, It works. But how do I know its json content? The File::Fetch document does not explain the scalar content is json.


    All is well. I learn by answering your questions...

      You could start by checking the MIME type:

      #!/usr/bin/env perl use strict; use warnings; use LWP::UserAgent; my $ua = LWP::UserAgent->new; my @urls = ( 'https://jsonplaceholder.typicode.com/todos/1', 'https://www.perl.org/' ); for my $url (@urls) { my $res = $ua->get ($url); print index($res->header('Content-Type'), 'application/json') > -1 + ? "$url is JSON\n" : "$url is not JSON\n"; }

      🦛

      File::Fetch just downloades content, it doesn't create.