As such I keep tearing down my past efforts -- but just so you know I am working on this instead of just waiting for others to do my work for me ...
Which produces the following output:sub recurse { my ($ref, $car, @cdr) = @_; if ($prev_car eq $car) { my $hash = { name => $car, children => [] }; push @$ref, $hash; return unless @cdr; $prev_car = $car; recurse($hash->{children}, @cdr); } push @$ref, { name => $car, children => [] }; return unless @cdr; $prev_car = $car; recurse($ref, @cdr); }
$VAR1 = [ { 'name' => 'one', 'children' => [] }, { 'name' => 'foo', 'children' => [] }, { 'name' => 'bar', 'children' => [] }, { 'name' => 'foo', 'children' => [ { 'name' => 'baz', 'children' => [] } ] }, { 'name' => 'foo', 'children' => [] }, { 'name' => 'baz', 'children' => [] }, { 'name' => 'foo', 'children' => [ { 'name' => 'qux', 'children' => [] }, { 'name' => 'two', 'children' => [] } ] }, { 'name' => 'foo', 'children' => [] }, { 'name' => 'qux', 'children' => [] }, { 'name' => 'two', 'children' => [] }, { 'name' => 'foo', 'children' => [] }, { 'name' => 'qux', 'children' => [] }, { 'name' => 'three', 'children' => [] }, { 'name' => 'foo', 'children' => [] }, { 'name' => 'qux', 'children' => [] }, { 'name' => 'four', 'children' => [] }, { 'name' => 'five', 'children' => [] } ];
In reply to Re^2: Convert delimited string into nested data structure
by Anonymous Monk
in thread Convert delimited string into nested data structure
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |