in reply to Getting a parent of a sub (array|hash) in a complex variable
Hello igoryonya,
Well there is another module Data::DRef that you might find "kind of useful" for what you are trying to do. It does not search the complex data structures but simplifies the iteration and lookup. Maybe combining it with same a grep etc it will help you get what you want. I have put together a small sample of data extraction based on your sample of code and the module.
Sample of code bellow:
#!/usr/bin/perl use strict; use warnings; use Data::Dumper; use feature 'say'; use Data::DRef qw( :dref_access :key_access ); my $complex = { key_of_hash => { opt1 => 'val1', opt2 => 'val2', key_of_hash_of_hashes => { opt3 => 'val3', opt4 => 'val4', } }, key_of_arr => [ 38, 'abc', -1829, ['element0', 8979, 'something else'] ] }; # say get_value_for_dref($complex, 'key_of_arr.3.0'); # print Dumper get_value_for_key($complex, 'key_of_hash'); # say get_value_for_keys($complex, 'key_of_hash', 'key_of_hash_of_hash +es', 'opt3'); # print Dumper $complex;
Hope this helps, BR.
|
|---|