To extract information from a hash reference, first you need to dereference. You can either:
print ${$artifact}{uri},"\n";
In this specific case, you can omit the braces and just do:
print $$artifact{uri},"\n";
But be aware that that can be ambiguous so the style of notation doesn't always work for dereferencing.
Or the newer, and probably clearer notation (e.g. like object oriented)
print $artifact->{uri},"\n";
However, there is a BIG alarm bell here - bless
- this means you're manipulating an object, probably. Poking inside an object is VERY dirty. You shouldn't ever do it. Usually the object will contain an accessor method to give you the information you need. By convention, an _
prefix denotes private
e.g. 'don't mess with this'. (Not that you should anyway)
As noted in the comments - this is a JSON text string embedded within your object. So if you were really set on doing this - you can parse the JSON, turn it into a perl data structure, then use that.
But far more likely - the object you're manipulating has some accessor methods built in, and you should use them.
So given your example above:
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
use JSON;
my $hashref = {
_content => '{
"results" : [ {
"uri" : "http://localhost:port/myfile.tar"
} ]
}'
};
print Dumper \$hashref;
my $json = JSON->new();
my $json_ob = $json->decode( $hashref->{_content} );
print Dumper \$json_ob;
print $json_ob ->{results}->[0]->{uri};
However as mentioned in comments, you're using:
Artifactory::Client
which quite sensibly uses LWP
.
Every public method provided in this module returns a HTTP::Response object.
Referring the HTTP::Response
docs gives this sample:
if ($artifact->is_success) {
print $artifact->decoded_content;
}
else {
print STDERR $artifact->status_line, "\n";
}