The name keys seem redundant to me. If you want to generate a nested hash structure based on the key strings then the following (non-recursive) code may get you started:
use strict; use warnings; use Data::Dump::Streamer; my %hash; while (<DATA>) { chomp; my @elements = split /\s*\/\s*/; next if ! @elements; $hash{$elements[0]} = {} if ! exists $hash{$elements[0]}; my $subHash = $hash{shift @elements}; for (@elements) { $subHash->{$_} = {} unless exists $subHash->{$_}; $subHash = $subHash->{$_}; }; } Dump \%hash; __DATA__ one foo / bar foo / baz foo / qux / two foo / qux / three foo / qux / four five
Prints:
$HASH1 = { five => {}, foo => { bar => {}, baz => {}, qux => { four => {}, three => {}, two => {} } }, one => {} };
In reply to Re: Convert delimited string into nested data structure
by GrandFather
in thread Convert delimited string into nested data structure
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |