in reply to Re^3: How to improve introspection of an array of hashes
in thread How to improve introspection of an array of hashes

I'm sure someone has done something like this as well. Just couldn't find it.

I took your code for a spin in the real world using Google Contacts API. Here's the output from a json response converted to a Perl data structure using Mojo::JSON::decode_json:

HASH => { encoding => {}, feed => { HASH => { "author" => { ARRAY => { HASH => { email => { HASH => { "\\$t" => {} } }, name => { HASH => { "\\$t" => {} } }, }, }, }, "category" => { ARRAY => { HASH => { scheme => {}, term => {} +} } }, "entry" => { ARRAY => { HASH => { "app\\$edited" => { HASH => { "\\$t" => {}, "xmlns\\$app +" => {} } }, "category" => { ARRAY => { HASH => { scheme => {}, term +=> {} } } }, "content" => { HASH => { "\\$t" => {} } }, "gContact\\$birthday" => { HASH => { when => {} } }, "gContact\\$groupMembershipInfo" => { ARRAY => { HASH => + { deleted => {}, href => {} } } }, "gContact\\$nickname" => { HASH => { "\\$t" => {} } }, "gContact\\$relation" => { ARRAY => { HASH => { "\\$t" = +> {}, "rel" => {} } } }, "gContact\\$userDefinedField" => { ARRAY => { HASH => { +key => {}, value => {} } } }, "gContact\\$website" => { ARRAY => { HASH => { href => {}, label => {}, primary +=> {}, rel => {} } }, }, "gd\\$email" => { ARRAY => { HASH => { address => {}, label => {}, primary => {}, + rel => {} }, }, }, "gd\\$etag" => {}, "gd\\$extendedProperty" => { ARRAY => { HASH => { "\\$t" + => {}, "name" => {} } } }, "gd\\$im" => { ARRAY => { HASH => { address => {}, label => {}, primary => {}, + protocol => {}, rel => {} }, }, }, "gd\\$name" => { HASH => { "gd\\$additionalName" => { HASH => { "\\$t" => {} } +}, "gd\\$familyName" => { HASH => { "\\$t" => {}, " +yomi" => {} } }, "gd\\$fullName" => { HASH => { "\\$t" => {} } +}, "gd\\$givenName" => { HASH => { "\\$t" => {}, " +yomi" => {} } }, "gd\\$namePrefix" => { HASH => { "\\$t" => {} } +}, "gd\\$nameSuffix" => { HASH => { "\\$t" => {} } +}, }, }, "gd\\$organization" => { ARRAY => { HASH => { "gd\\$orgDepartment" => { HASH => { "\\$t" => {} } + }, "gd\\$orgName" => { HASH => { "\\$t" => {} } }, "gd\\$orgTitle" => { HASH => { "\\$t" => {} } }, "primary" => {}, "rel" => {}, }, }, }, "gd\\$phoneNumber" => { ARRAY => { HASH => { "\\$t" => {}, "label" => {}, "primary" => +{}, "rel" => {}, "uri" => {} }, }, }, "gd\\$structuredPostalAddress" => { ARRAY => { HASH => { "gd\\$city" => { HASH => { "\\$t" => { +} } }, "gd\\$country" => { HASH => { "\\$t" => { +}, "code" => {} } }, "gd\\$formattedAddress" => { HASH => { "\\$t" => { +} } }, "gd\\$postcode" => { HASH => { "\\$t" => { +} } }, "gd\\$region" => { HASH => { "\\$t" => { +} } }, "gd\\$street" => { HASH => { "\\$t" => { +} } }, "primary" => {}, "rel" => {}, }, }, }, "id" => { HASH => { "\\$t" => {} } }, "link" => { ARRAY => { HASH => { "gd\\$etag" => {}, "href" => {}, "rel" => +{}, "type" => {} }, }, }, "title" => { HASH => { "\\$t" => {} } }, "updated" => { HASH => { "\\$t" => {} } }, }, }, }, "gd\\$etag" => {}, "generator" => { HASH => { "\\$t" => {}, "uri" => {}, "version +" => {} } }, "id" => { HASH => { "\\$t" => {} } }, "link" => { ARRAY => { HASH => { href => {}, rel => {}, type = +> {} } } }, "openSearch\\$itemsPerPage" => { HASH => { "\\$t" => {} } }, "openSearch\\$startIndex" => { HASH => { "\\$t" => {} } }, "openSearch\\$totalResults" => { HASH => { "\\$t" => {} } }, "title" => { HASH => { "\\$t" => {} } }, "updated" => { HASH => { "\\$t" => {} } }, "xmlns" => {}, "xmlns\\$batch" => {}, "xmlns\\$gContact" => {}, "xmlns\\$gd" => {}, "xmlns\\$openSearch" => {}, }, }, version => {}, },

I modified the code slightly to get rid of the "SCALAR" output.

$PM = "Perl Monk's";
$MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest";
$nysus = $PM . ' ' . $MCF;
Click here if you love Perl Monks

Replies are listed 'Best First'.
Re^5: How to improve introspection of an array of hashes
by Eily (Monsignor) on Sep 13, 2018 at 16:50 UTC

    I modified the code slightly to get rid of the "SCALAR" output.
    I should have thought of that xD.

    What did you use for the output, I'm guessing it's not Data::Dump? "author" => {} would normally not have the quotes, and I don't understand how you can get something like "\\$t", where the backslash is escaped, so $t gets interpolated which would normally not happen with a either Data::Dumper or Data::Dump.

      Ah, sorry, yeah. That those double backslashes were an artifact of my logging script which uses Dumper. I'll have to look into replacing that with pp. Anyway, here is the raw output from pp:
      HASH => { encoding => {}, feed => { HASH => { "author" => { ARRAY => { HASH => { email => { HASH => { "\$t" => {} } }, name => { HASH => { "\$t" => {} } }, }, }, }, "category" => { ARRAY => { HASH => { scheme => {}, term => {} +} } }, "entry" => { ARRAY => { HASH => { "app\$edited" => { HASH => { "\$t" => {}, "xmlns\$app" = +> {} } }, "category" => { ARRAY => { HASH => { scheme => {}, term +=> {} } } }, "content" => { HASH => { "\$t" => {} } }, "gContact\$groupMembershipInfo" => { ARRAY => { HASH => +{ deleted => {}, href => {} } } }, "gContact\$userDefinedField" => { ARRAY => { HASH => { k +ey => {}, value => {} } } }, "gd\$email" => { ARRAY => { HASH => { address => {}, primary => {}, rel + => {} } }, }, "gd\$etag" => {}, "gd\$extendedProperty" => { ARRAY => { HASH => { "\$t" = +> {}, "name" => {} } } }, "gd\$name" => { HASH => { "gd\$familyName" => { HASH => { "\$t" => {} } }, "gd\$fullName" => { HASH => { "\$t" => {} } }, "gd\$givenName" => { HASH => { "\$t" => {} } }, }, }, "gd\$phoneNumber" => { ARRAY => { HASH => { "\$t" => {}, "primary" => {}, "rel" => {}, + "uri" => {} }, }, }, "id" => { HASH => { "\$t" => {} } }, "link" => { ARRAY => { HASH => { "gd\$etag" => {}, "href" => {}, "rel" => { +}, "type" => {} }, }, }, "title" => { HASH => { "\$t" => {} } }, "updated" => { HASH => { "\$t" => {} } }, }, }, }, "gd\$etag" => {}, "generator" => { HASH => { "\$t" => {}, "uri" => {}, "version" + => {} } }, "id" => { HASH => { "\$t" => {} } }, "link" => { ARRAY => { HASH => { href => {}, rel => {}, type = +> {} } } }, "openSearch\$itemsPerPage" => { HASH => { "\$t" => {} } }, "openSearch\$startIndex" => { HASH => { "\$t" => {} } }, "openSearch\$totalResults" => { HASH => { "\$t" => {} } }, "title" => { HASH => { "\$t" => {} } }, "updated" => { HASH => { "\$t" => {} } }, "xmlns" => {}, "xmlns\$batch" => {}, "xmlns\$gContact" => {}, "xmlns\$gd" => {}, "xmlns\$openSearch" => {}, }, }, version => {}, },

      $PM = "Perl Monk's";
      $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest";
      $nysus = $PM . ' ' . $MCF;
      Click here if you love Perl Monks

        By the way, do you have an idea on what the significance of the dollar sign in a json key is? I've never seen that before. I googled a bit but didn't find anything definitive about it.

        $PM = "Perl Monk's";
        $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest";
        $nysus = $PM . ' ' . $MCF;
        Click here if you love Perl Monks