Q:

Perl Newbie - Printing value from array

I am brand new to perl. I am trying to grab a string out of some JSON output. My code below works, but seems like there is a smarter way to do this. Here is a sample of the JSON
$VAR1 = '{
    "hasDetailRows" : true,
     "reportMetadata" : {
     "reportFormat" : "TABULAR",
    "detailColumns" : [ "SUBJECT", "COMMENT_CREATED_DATE", "CASE_COMMENT_CREATED_BY" ],
    "reportBooleanFilter" : null,
    "reportFilters" : [ {
      "column" : "CASE_COMMENT_CREATED_BY",
      "operator" : "equals",
      "value" : "Username"
    } ],
    "aggregates" : [ "RowCount" ],
    "groupingsDown" : [ ],
    "groupingsAcross" : [ ],
    "developerName" : "My_Comments",
    "reportType" : {
      "type" : "CaseList",
      "label" : "Cases"
    },
    "name" : "My Comments",
    "id" : "REDCATED",
    "currency" : null
  },
      "factMap" : {
       "T!T" : {
        "rows" : [ {
        "dataCells" : [ {
          "value" : "ID",
          "label" : "Description"
        }, {
          "value" : "2014-02-17T22:01:17Z",
          "label" : "2/17/2014 4:01 PM"
        }, {
          "value" : "USER ID",
          "label" : "User Name"
        } ]
      }`

What I need is that label with the timestamp.
And here is my code
#!/usr/bin/perl
use warnings;
use strict;
use WWW::Mechanize;
use WWW::Salesforce;
use Data::Dumper;
use JSON -support_by_pp;
use 5.010;
use Date::Parse;

my $mech = WWW::Mechanize->new();
$mech->agent('Mozilla/5.0');

# Authenticate first via SOAP interface to get a session ID:
my $sforce = eval { WWW::Salesforce->login(

                    username => 'REDACTED',
                    password => 'REDACTED' ); };
die "Could not login to SFDC: $@" if $@;

 # Get the session ID:
my $hdr = $sforce->get_session_header();
my $sid = ${$hdr->{_value}->[0]}->{_value}->[0];

#Our request
$mech->add_header( "Authorization" => "OAuth $sid" );
$mech->add_header( "X-PrettyPrint" => '1' );
$mech->get("SOME URL THAT RETURNS JSON");
my $content =  $mech->content;

my $json = new JSON;
my $json_text =    $json->allow_nonref->utf8->relaxed->escape_slash->loose->allow_singlequote->allow_barekey->decode($content);

Here is what I have currently that grabs the value that I want from $content. All I need is the first result which is why I am killing the loop after the first run. Everytime I have tried this without a loop I get "Not a HASH reference". So all I need to know is the correct syntax for printing out the value of $timestamp.
foreach my $field(@{$json_text->{factMap}->{'T!T'}->{rows}}){
  my $now = time();

my $timestamp = str2time($field->{dataCells}[1]->{'label'});
my $diff = int (($now - $timestamp)/60);
my $current = getLoggingTime();
print  $current . " \t";
say "Time since last activity: " . $diff . " minutes!" ;
  last;
 }

sub getLoggingTime {

my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time);
my $nice_timestamp = sprintf ( "%04d-%02d-%02d %02d:%02d:%02d",
                               $year+1900,$mon+1,$mday,$hour,$min,$sec);
return $nice_timestamp; 
} 

A:

I don't know what your without-a-loop version looks like, but this should work:
my $timestamp = str2time(
    $json_text->{factMap}{'T!T'}{rows}[0]{dataCells}[1]{label}
);

Currently, you're looping over the elements of the array referenced by 
$json_text->{factMap}{'T!T'}{rows}

...and stopping at the first entry
$json_text->{factMap}{'T!T'}{rows}[0]

...and dereferencing that to get to
$json_text->{factMap}{'T!T'}{rows}[0]{dataCells}[1]{label}

