Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re: Parsing a Tree to a Table.

by hdb (Prior)
on Dec 10, 2013 at 08:30 UTC ( #1066400=note: print w/ replies, xml ) Need Help??

in reply to Parsing a Tree to a Table.

Very nice puzzle. Here is my solution:

use warnings; use strict; my @path; my @data; my $size = 0; while(<DATA>) { chomp; $path[0] = $1 if /^([^|]*)$/; $path[length($1)/3] = $2 if /^(.*\|--)([^-]+)$/; if( /^(.*\|--)-([^-]+)$/ ) { $#path = length($1)/3 - 1; push @data, [ @path, $2 ]; $size = @path if $size < @path; } } splice @$_, -1, 0, ('')x(1+$size-@$_) for @data; print join( "\t", @$_ ),"\n" for @data; __DATA__ A | |--B | | | |--C | | | |---PQR | |---XYZ |--D | | | |---LMN |---XYZ

Comment on Re: Parsing a Tree to a Table.
Download Code

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1066400]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2015-03-05 08:30 GMT
Find Nodes?
    Voting Booth?

    When putting a smiley right before a closing parenthesis, do you:

    Results (136 votes), past polls