Hello everyone, I got a task to write a Perl script to test our API. So far so good code below

use strict; use warnings; use JSON; use JSON::Parse 'parse_json'; print "Loading API.\n"; my $json = `curl -k --silent -u admin:password https://url...`; print "API is loaded.\n"; my $decoded_json = parse_json ($json); my $input = $ARGV[0]; chomp $input; my ($item, $mac, $value); foreach $item (@$decoded_json) { $mac = $item->{address}; if ($input eq "active") { $value = $item->{active}; if ($value eq 1){ print ("Device with the MAC-Adress: $mac is active!\n"); }elsif($value eq ""){ print ("Device with the MAC-Adress: $mac is disabled!\n"); }}else{ print ("Device with the MAC-Adress: $mac, the value of $input +is: ", $item->{$input}, "\n"); } };

Is it possible to replace the loop and if statments, so the asked parameter like "active=true", with curl? So the true values get saved in $json. Basicly, execute the request with just curl code. For example if I start it: perl test.pl active=true, so it outputs only the active true values?


In reply to Getting values with help of curl by PerlMonkey22

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.