1
2
3
4
5
...
my $decoded = decode_json( $response->content );
if ($type eq "local") {
print Dumper(\%$decoded); #only with: use Data::Dumper;
my $value = $decoded->{data}->{tuples}[0][1]; # < Hier kommt der Fehler: not a hash refence
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
$VAR1 = {
'version' => '1',
'data' => [
{
'protocol' => 'x',
'tuples' => [
[
'1424006943281',
'15098'
]
],
'last' => '1424006943281',
'interval' => 30,
'uuid' => '180'
}
],
'generator' => 'a'
};
my $value = $decoded->{data}->[0]->{tuples}[0][1];
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
#! /usr/bin/perl use strict; use warnings; use 5.010.000; my $data = { foo => [ { bar => 123 }, ], }; # keep this declaration outside of the eval-block my $val = "not defined"; # this with error eval { $val = $data->{foo}->{bar}; }; warn "$@\n" if $@; # check say "I'm alive and val is: $val"; # this hopefully without error eval { $val = $data->{foo}->[0]->{bar}; }; warn "$@\n" if $@; # check again say "I'm still alive and val is: $val";
Guest perl_gastCode: (dl )print Dumper(\%$decoded);