I am trying to fetch a url from artifactory using File::Fetch module. I have only this module install on the server, I can't install other modules. Below is the part of the code.

my $jar='xxxxxx.jar'; my $url = "http://ip_address:port/artifactory/api/search/artifact?name +=".$jar."&repos=xxxxx-3rdparty-libs-local,Central_Maven_repository-ca +che,Jcenter,Jcenter-cache,FuseSource,MavenRedHat,ApacheArchive,Centra +l_Maven_2_repository-cache,xxxxx-3rdparty-libs-common,Central_Maven_2 +_repository,Central_Maven_repository,Jcenter and Gradle-Remote"; my $response; my $ff = File::Fetch->new(uri => $url); $ff->fetch( to => \$response) or die $ff->error; print Dumper $response;

I am fetching the url into a scalar variable and it prints as,

$VAR1 = '{ "results" : [ { "uri" : "http://ipaddress:port/artifactory/api/storage/Central_Mav +en_2_repository-cache/org/xxxxx.jar" }, { "uri" : "http://ipaddress:port/artifactory/api/storage/xxxxx-3rdpa +rty-libs-local/org/xxxxx.jar" } ] }';

Initially I thought it is a hash ref, and tried to access as,

print $response->{'results'};

But got blow error

Can't use string ("{ "results" : [ { "uri" : "...) as a SCALAR ref while "strict refs" in use at artifa +ctory_url.pl line 39.

I need the first uri available in the $response variable? How to convert this string to hash ref ?

For now I used below code to parse the first uri from the response, I hope there should be a better way to get the first uri from the response.

if ($response =~/"uri" : "(.*?)"/){ print($1."\n"); }else{ print("Fetch failed\n"); }

All is well. I learn by answering your questions...

In reply to File::Fetch fetch to scalar by vinoth.ree

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.