Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Parsing a Tree to a Table.

by hdb (Parson)
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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (12)
As of 2014-08-21 13:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (135 votes), past polls