Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

From the foolowing data structure, how can I retrieve a list of keys?
$VAR1 = '0x10040'; $VAR2 = { '' => {}, 'ZoomScale' => { 'Flags' => 'R,W,D', 'Id' => '0x11b2c', 'Type' => 'Integer', 'Name' => 'ZoomScale' }, 'Model_State' => { 'Flags' => 'R,W,M,D', 'Id' => '0x1007c', 'Type' => 'Integer', 'Name' => 'Model_State' }, 'View_Description_List' => { 'Flags' => 'R,W,D', 'Id' => '0x11f48', 'Type' => 'Tagged Octet', 'Name' => 'View_Description_Lis +t' }, 'mdl_modfy_athr' => { 'Flags' => 'R,W,D', 'Id' => '0x11025', 'Type' => 'Text String', 'Name' => 'mdl_modfy_athr' }, 'IfOrgRel' => { 'Flags' => 'R,W,S,D', 'Id' => '0x11b4d', 'Type' => 'Relation Handle', 'Name' => 'IfOrgRel' }, 'Collected_By_List' => { 'Flags' => 'R,W,M,D', 'Id' => '0x10c48', 'Type' => 'Octet String', 'Name' => 'Collected_By_List' }, 'createtime' => { 'Flags' => 'R,D', 'Id' => '0x11b41', 'Type' => 'Date', 'Name' => 'createtime' }, 'Is_Device' => { 'Flags' => 'R,W,S,D', 'Id' => '0x11f4a', 'Type' => 'Boolean', 'Name' => 'Is_Device' }, 'Rollup_Condition' => { 'Flags' => 'R,W,G,M', 'Id' => '0x10013', 'Type' => 'Integer', 'Name' => 'Rollup_Condition' },
I'm trying to populate an array with the following keys:
ZoomScale model_State View_Description_List . . .

Replies are listed 'Best First'.
Re: Retrieving a list of keys from a hash of hashes
by broquaint (Abbot) on Apr 01, 2003 at 14:14 UTC
    /me suggests
    my @keys = keys %{ $hash{'0x10040'} };
    See. perlreftut for more info.
    HTH

    _________
    broquaint

Re: Retrieving a list of keys from a hash of hashes
by robartes (Priest) on Apr 01, 2003 at 14:15 UTC
    To get the list of keys of the hash pointed to by $VAR2, you dereference the hashref:
    my @keys = keys %$VAR2;
    The same goes for getting the keys of a next level hash: dereference the hashref, which in this case happens to be a hash value as well:
    my @keys2 = keys %{$VAR2->{'Model_State'}};
    For more information, have a look at perlreftut, perlref and perldsc.

    Update: Ugh, this was output from Data::Dumper::Dumper of a hash. BrowserUK broquaint spotted this well. His solution is probably a direct plug in for your program.

    CU
    Robartes-

Re: Retrieving a list of keys from a hash of hashes
by zby (Vicar) on Apr 01, 2003 at 14:21 UTC
    So you say it is just one hash. I gues you write it down with code simmilar to print Dumper(%yourhash). Then you can get the list with keys %{$yourhash{'0x10040'}}.