Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Parsing a Tree to a Table.

by hdb (Monsignor)
on Dec 10, 2013 at 08:30 UTC ( [id://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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2024-04-23 22:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found