Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: reading a text file into hash

by pme (Prior)
on Jun 30, 2015 at 08:23 UTC ( #1132583=note: print w/replies, xml ) Need Help??


in reply to reading a text file into hash

Hi AM,

This text looks like JSON (http://json.org). JSON can be easily processed by JSON or JSON::XS modules.

use strict; use warnings; use Data::Dumper; use JSON; my $json_text = q{ { "InstanceStatuses": [ { "InstanceId": "i-308c0b3c", "InstanceState": { "Code": 16, "Name": "running" }, "AvailabilityZone": "us-west-2b", "SystemStatus": { "Status": "ok", "Details": [ { "Status": "passed", "Name": "reachability" } ] }, "InstanceStatus": { "Status": "ok", "Details": [ { "Status": "passed", "Name": "reachability" } ] } } ] } }; # decode JSON text my $hashref = decode_json $json_text; # dump the hashref print Dumper( $hashref ) . "\n"; # access Name print "Name: '$hashref->{InstanceStatuses}->[0]->{InstanceState}->{Nam +e}'\n";

Replies are listed 'Best First'.
Re^2: reading a text file into hash
by Anonymous Monk on Jun 30, 2015 at 09:01 UTC

    Hi pme, Thanks a lot for your help.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1132583]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (11)
As of 2020-01-21 16:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?