in reply to Re^3: Convert delimited string into nested data structure
in thread Convert delimited string into nested data structure

Hi. Thanks for the code, but it has an awful lot of syntax errors in it. Here is the corrected version:
foreach my $input ( @inputs ) { my @pieces = split /\s+\/\s+/, $input; my $level = scalar @pieces; my $new_node = { name => $pieces[-1], level => $level }; if ( $level == $stack[-1]->{level} ) { pop @stack; } elsif ( $level < $stack[-1]->{level} ) { pop @stack while ( $level <= $stack[-1]->{level} ); } # else top level must be our parent push @{ $stack[-1]->{children} }, $new_node; push @stack, $new_node; }
Anyways ... this works like a charm. Thanks a lot. :)