in reply to reading a text file into hash
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 |