ovedpo15 has asked for the wisdom of the Perl Monks concerning the following question:
{ "/": { "type": "dir", "files": [ { "p": { "type": "dir-link", "source": "/nfs/data/project", "files": [ { "xa": { "type": "dir", "files": [ { "tools": { "type": "dir", "files": [ { "sd": { "type": "dir", "files": [ { "su2av": { "type": "dir", "files": [ { "duf": { "type": "dir", "files": [ { "0.4.0": { "type": "dir-link", "source": "/nfs/vsa/proj +ect/xa/vuvua/su2av", "files": [ { "bin": { "type": "dir", "files": [ { "duf": { "type": "lin +k-file", "source": ". +run" } }, { ".run": { "type": "fil +e" } } ] } } ] } } ] } } ] } } ] } } ] } } ] } } ] } }, { "nfs": { "type": "dir", "files": [ { "data": { "type": "dir", "files": [ { "project": { "type": "dir", "files": [] } } ] } }, { "vsa": { "type": "dir", "files": [ { "project": { "type": "dir", "files": [ { "xa": { "type": "dir", "files": [ { "vuvua": { "type": "dir", "files": [ { "su2av": { "type": "dir", "files": [] } } ] } } ] } } ] } } ] } } ] } } ] } }
For links it will be a bit different because I should have source and target so I will do this part myself. How can I get all the paths (dirs/files)? I thought of using recursion as I don't know how deep the nested hash is. How can I do it without grep? my code to test it:/p/xa/tools/sd/su2av/duf/0.4.0/bin /nfs/data/project /nfs/vsa/project/xa/vuvua/su2av
my $j = '{ "/": { "type": "dir", "files": [ { "p": { "type": "dir-link +", "source": "/nfs/data/project", "files": [ { "xa": { "type": "dir", + "files": [ { "tools": { "type": "dir", "files": [ { "sd": { "type": +"dir", "files": [ { "su2av": { "type": "dir", "files": [ { "duf": { " +type": "dir", "files": [ { "0.4.0": { "type": "dir-link", "source": " +/nfs/vsa/project/xa/vuvua/su2av", "files": [ { "bin": { "type": "dir" +, "files": [ { "duf": { "type": "link-file", "source": ".run" } }, { +".run": { "type": "file" } } ] } } ] } } ] } } ] } } ] } } ] } } ] } +} ] } }, { "nfs": { "type": "dir", "files": [ { "data": { "type": "di +r", "files": [ { "project": { "type": "dir", "files": [] } } ] } }, { + "vsa": { "type": "dir", "files": [ { "project": { "type": "dir", "fi +les": [ { "xa": { "type": "dir", "files": [ { "vuvua": { "type": "dir +", "files": [ { "su2av": { "type": "dir", "files": [] } } ] } } ] } } + ] } } ] } } ] } } ] } }'; my $obj = decode_json($j);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to iterate over nested hash and get all paths?
by tybalt89 (Monsignor) on Mar 27, 2021 at 18:34 UTC | |
|
Re: How to iterate over nested hash and get all paths?
by Arunbear (Prior) on Mar 27, 2021 at 18:38 UTC | |
|
Re: How to iterate over nested hash and get all paths?
by AnomalousMonk (Archbishop) on Mar 27, 2021 at 18:09 UTC | |
|
Re: How to iterate over nested hash and get all paths?
by LanX (Saint) on Mar 27, 2021 at 16:53 UTC | |
|
Re: How to iterate over nested hash and get all paths?
by perlfan (Parson) on Mar 27, 2021 at 15:41 UTC | |
|
Re: How to iterate over nested hash and get all paths? (JSON::Path Data::Diver)
by Anonymous Monk on Mar 27, 2021 at 21:36 UTC | |
|
Re: How to iterate over nested hash and get all paths?
by LanX (Saint) on Mar 28, 2021 at 00:49 UTC |