in reply to Re^3: Running JavaScript from within Perl (or just use the API)
in thread Running JavaScript from within Perl

I was previously given the example:

my $subscribers = $ua->get( $url )->result->json->{subscribers_count};

which I modified (based on this JSON Tutorial) to:

my $feedurl = $ua->get($url)->result->json->{feeds.meta.links.feed};

which gave error message:

Bareword "feeds" not allowed while "strict subs" in use

I'll keep exploring but would appreciate any hints.

Replies are listed 'Best First'.
Re^5: Running JavaScript from within Perl (or just use the API)
by haukex (Archbishop) on Sep 21, 2019 at 12:37 UTC
    my $feedurl = $ua->get($url)->result->json->{feeds.meta.links.feed}; which gave error message: Bareword "feeds" not allowed while "strict subs" in use

    Only very simple barewords are automatically quoted in $hash{...} keys, the . is seen as an operator here. Try ...->json->{'feeds.meta.links.feed'};.

    Update: See Re: hash key.

Re^5: Running JavaScript from within Perl (or just use the API)
by marto (Cardinal) on Sep 21, 2019 at 16:31 UTC

    Lets take it back a step, there's various ways to achieve what you want. Perhaps this example is clearer:

    #!/usr/bin/perl use strict; use warnings; use Mojo::UserAgent; my $url = 'https://public-api.wordpress.com/rest/v1/read/feed/?url=the +-art-of-autism.com'; my $ua = Mojo::UserAgent->new; my $json = $ua->get( $url )->res->json; for my $feed ( @{$json->{feeds}} ){ if ( $feed->{meta}{links}{feed} ){ print "$feed->{meta}{links}{feed}\n"; } }

    For each entry in feeds, print the value of meta->links->feed.

    Update: see Re^4: Running JavaScript from within Perl (or just use the API).