title: Perl - from JSON to object/ hash
body: <p>I have to code below:</p>
  
  <pre><code>#!/usr/intel/bin/perl
  
  use strict;
  use warnings;
  
  use JSON::XS;
  
  my $json = '{"Object1":{"Year":"2012","Quarter":"Q3","DataType":"Other 3","Environment":"STEVE","Amount":125},"Object2":{"Year":"2012","Quarter":"Q4","DataType":"Other 2","Environment":"MIKE","Amount":500}}';
  
  my $arrayref = decode_json $json;
  
  for my $array(@$arrayref){
          for my $key (keys(%$array)){
                  my $val = $array-&gt;{$key};
                  print "$key: $val\n";
          }
  
  }
  </code></pre>
  
  <p>When I compile it, it print me the error "Not an ARRAY reference at generator.pl line 12.".</p>
  
  <p>I want to parse the JSON to an object and get data according to the object with the attributes. How can I do it?</p>
  
  <p>I expect after I parse it, I can use to compare string, print, loop it and so on.</p>