in reply to Dynamic Dereferencing

You may be interested in Data::Diver. I also showed some custom "diver" type code here and here. Update: There's also Data::DPath or Data::Path, I haven't used these myself but they seem worth a look.

Replies are listed 'Best First'.
Re^2: Dynamic Dereferencing
by Flip76 (Novice) on Dec 07, 2018 at 13:15 UTC
    Thanks, I will give it a try

      If you know your data then maybe a simplified version of the code in Data::Diver is all you need.

      #!perl use strict; use JSON qw 'decode_json'; my $json = join '',<DATA>; $json =~ s/\n//g; my $data_structure = decode_json($json); my @elements = qw(userName displayName meta.created ); for my $item ( @{ $data_structure->{Resources} } ){ for my $e (@elements){ my $ref = $item; my @keys = split '\.',$e; while (@keys){ my $key = shift @keys; $ref = $ref->{$key}; } printf "$e = %s\n",$ref; } print "\n"; } __DATA__ {"Resources":[ {"id":"1234567","userName":"user1@test.com", "meta":{"created":"2018-04-16T11:57:19.376Z"},"displayName":"User 1"}, {"id":"1234568","userName":"user2@test.com", "meta":{"created":"2018-04-16T11:59:27.111Z"},"displayName":"User 2"}, {"id":"12345679","userName":"user3@test.com", "meta":{"created":"2018-11-21T14:49:33.821Z"},"displayName":"User 3"} ],"schemas":["urn:ietf:params:scim:api:messages:2.0:ListResponse"], "startIndex":1,"itemsPerPage":50,"totalResults":3}
      poj