in reply to Re: File::Fetch fetch to scalar
in thread File::Fetch fetch to scalar

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...

Replies are listed 'Best First'.
Re^3: File::Fetch fetch to scalar
by hippo (Archbishop) on Jul 03, 2021 at 09:05 UTC

    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"; }

    🦛

Re^3: File::Fetch fetch to scalar
by Anonymous Monk on Jul 03, 2021 at 08:41 UTC
    File::Fetch just downloades content, it doesn't create.