in reply to Re^2: Parsing Output
in thread Parsing Output

then it gave me an error response that it did not know what Data::Dump was.

Sure it knows:

$ cpan -D Data::Dump Reading '/home/redacted/.cpan/Metadata' Database was generated on Wed, 23 Feb 2022 09:55:53 GMT Data::Dump ---------------------------------------------------------------------- +--- (no description) G/GA/GARU/Data-Dump-1.25.tar.gz (no installation file) Installed: not installed CPAN: 1.25 Not up to date Breno G. de Oliveira (GARU) garu@cpan.org

Why describe the error messages when you could simply paste them?


🦛

Replies are listed 'Best First'.
Re^4: Parsing Output
by PerlMonger79 (Sexton) on Feb 23, 2022 at 15:13 UTC
    Hi again. So I was able to install the module and I added the code to my script and got a few errors but also the same output as yours. Please find my code and output below. Is there something I must fix?
    #!/usr/bin/perl -w use strict; use warnings; use JSON; use LWP::UserAgent; require HTTP::Cookies; my $netloc = "xxx.xx.xx.xx:80"; my $realm = "Realm"; my $user = "username"; my $pass = "password"; my $auth_token = "token code"; my $ua = new LWP::UserAgent; $ua->agent('Mozilla/5.0'); my $cookie_jar = HTTP::Cookies->new( file => 'cookies_lwp.txt', autosa +ve => 1, ignore_discard => 1 ); $ua->cookie_jar($cookie_jar); $ENV{PERL_LWP_SSL_VERIFY_HOSTNAME}=0; $ua->default_header( "Authorization" => "Bearer $auth_token"); $ua->default_header( "Accept" =>"application/json" ); $ua->default_header( "Content-Type" => "application/json"); $ua->credentials( $netloc, $realm, $user, $pass); $ua->ssl_opts( verify_hostname => 0, SSL_verify_mode => 0x00); my $request = new HTTP::Request('GET','https://xxx.xx.xx.xx/api/v2/dev +ices/00:04:56:22:51:32/performance/?start_time=2022-02-15T10:00:00&st +op_time=2022-02-16T10:00:00'); my $response = $ua->request($request); if ($response->is_success) { my $output = $response->decoded_content; #print $output."\n"; #Code from perlmonks use JSON::PP; my $data = join '', $output; my $hashref = JSON::PP->new->decode($data); use Data::Dump 'dd'; dd $hashref; } else { print STDERR $response->status_line, "\n"; }
    Output:
    Subroutine main::encode_json redefined at /usr/local/share/perl5/Expor +ter.pm line 66. at ./wifi-api-get.pl line 33. Subroutine main::decode_json redefined at /usr/local/share/perl5/Expor +ter.pm line 66. at ./wifi-api-get.pl line 33. Prototype mismatch: sub main::decode_json ($) vs none at /usr/local/sh +are/perl5/Exporter.pm line 66. at ./wifi-api-get.pl line 33. Subroutine main::from_json redefined at /usr/local/share/perl5/Exporte +r.pm line 66. at ./wifi-api-get.pl line 33. Prototype mismatch: sub main::from_json ($@) vs ($) at /usr/local/shar +e/perl5/Exporter.pm line 66. at ./wifi-api-get.pl line 33. Subroutine main::to_json redefined at /usr/local/share/perl5/Exporter. +pm line 66. at ./wifi-api-get.pl line 33. Prototype mismatch: sub main::to_json ($@) vs ($) at /usr/local/share/ +perl5/Exporter.pm line 66. at ./wifi-api-get.pl line 33. { data => [ { mac => "00:04:56:22:51:32", managed_account => "", mode => "ap", name => "Espat AP3", network => "Belize City ePMP", online_duration => 3600, radio => { dl_frame_utilization => 53.50833, dl_kbits => 218936297, dl_pkts => 24533891, dl_retransmits_pct => 3.7125, dl_throughput => 60611.05917, ul_kbits => 11781720, ul_pkts => 10095078, ul_retransmits_pct => 1.7481, ul_throughput => 3261.45, }, sm_count => 45, sm_drops => 1, timestamp => "2022-02-15T04:00:00-06:00", tower => "Espat Twr", type => "epmp", uptime => 3600, }, { mac => "00:04:56:22:51:32", managed_account => "", mode => "ap", name => "Espat AP3", network => "Belize City ePMP", online_duration => 3600, radio => { dl_frame_utilization => 55.79167, dl_kbits => 228622837, dl_pkts => 25268171, dl_retransmits_pct => 3.4875, dl_throughput => 63241.6925, ul_kbits => 11064503, ul_pkts => 10404746, ul_retransmits_pct => 1.6548, ul_throughput => 3060.63917, }, . . . . rest of the output similar to your output.

      You've used both JSON and JSON::PP in your code; don't do that. The former is a "smart" module that will pick the faster available backend between the pure perl version and JSON::XS if available. Since the first import has already pulled in the subs named when the second use is encountered perl is warning you that you're redefining things it already knows about.

      The cake is a lie.
      The cake is a lie.
      The cake is a lie.

Re^4: Parsing Output
by PerlMonger79 (Sexton) on Feb 23, 2022 at 14:45 UTC
    Ok, I tried it again just now and it gave me a different error. Seems connection to the internet has been blocked by the network admin. The server is on a private LAN.. so once I get the access again I'll try installing the module again. I'll keep you posted, and thanks again for taking time in helping me. I appreciate it very much.