Looks like this gives the data structure you wanted.
#!/usr/bin/perl use strict; use warnings; use Data::Dumper; $Data::Dumper::Indent = 1; my $tree; my @refs; while (<DATA>) { chomp; my ($prefix) = /^(\s+)/; s/^$prefix// if $prefix; my $lvl = $prefix ? (length $prefix) / 2 : 0; my $rec = { label => $_, children => [] }; $refs[$lvl] = $rec; $#refs = $lvl; if ($tree) { push @{$refs[$lvl - 1]->{children}}, $rec; } else { $tree = $rec; } } print Dumper $tree; __DATA__ Building House Window Glas Silicium Door Roof Wood Hut Pizza Garage Door
"The first rule of Perl club is you do not talk about
Perl club."
-- Chip Salzenberg
In reply to Re: tree in hash
by davorg
in thread tree in hash
by Murcia
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |