hello I am having an issue taking a perl API call that is in JSON i want to get all subdomains from this link
#!/usr/bin/perl
use strict;
use warnings;
use HTTP::Request;
use LWP::UserAgent;
use HTTP::Response;
use HTTP::Request::Common qw(POST);
use HTTP::Request::Common qw(GET);
use Data::Dumper;
use LWP::Simple;
use JSON qw( decode_json encode_json );
my $ua = LWP::UserAgent->new;
$ua = LWP::UserAgent->new(keep_alive => 1);
$ua->agent("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.63 Safari/537.31");
my $url = "https://www.threatcrowd.org/searchApi/v2/domain/report/?domain=fb.com";
my $request = $ua->get($url);
my $response = $request->content;
my $decoded = decode_json($response);
print $decoded->{'subdomains'};
and if run this script get this
C:\Users\USER\Desktop>1.pl
ARRAY(0x625c868
If it is truly a simple array reference (you can check by using Data::Dumper), you need to iterate over the list and print each element/item:
for my $element (@{ $decoded->{'subdomains'} }){
print "$element\n";
}
That @{}
syntax is a dereference operator. It dereferences the array reference held in the variable within its braces.
See the Using References section in the perlreftut documentation for more information.