Jeremy Wilson
Jeremy Wilson

Reputation: 509

Perl - Get value in nested array of arrays

I have a variable ($issue) that contains various values that I need to pull a single value (emailAddress) from. The contents of $issue (via Data::Dump) is:

'fields' => {
    'reporter' => {
        'name' => 'jeremywilson',
            'displayName' => 'Jeremy Wilson',
            'key' => '15429',
            'emailAddress' => '[email protected]',
            'timeZone' => 'America/New_York',
            'active' => bless( do{\(my $o = 1)}, 'JSON::PP::Boolean' )
    },
    'customfield' => [
        {
            'active' => $VAR1->{'fields'}{'reporter'}{'active'},
            'timeZone' => 'America/New_York',
            'emailAddress' => '[email protected]',
            'key' => 'mexample',
            'name' => 'mexample',
            'displayName' => 'Mike Example'
        }
    ],
}

I get the first email via $issue->{fields}->{'reporter'}->{'emailAddress'} but how do I get the value from customfield?

Upvotes: 0

Views: 95

Answers (1)

David Dyck
David Dyck

Reputation: 128

The comments include two answers

$issue->{fields}->{customfield}[0]->{emailAddress}

and a shorter, but also correct

$issue->{fields}{customfield}[0]{emailAddress}

These answer the question that was asked, but likely, more clarification is needed for a general answer, for example, when there are more than one customfield, or if customfield is optional, how will the data be represented?

Upvotes: 1

Related Questions