Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: reparse tree in textfile

by ikegami (Patriarch)
on Feb 19, 2010 at 07:23 UTC ( #824112=note: print w/replies, xml ) Need Help??


in reply to reparse tree in textfile

use strict; use warnings; my @levels = '.'; while (<DATA>) { chomp; my ($prefix, $node) = split(/(?<=-- )/, $_, 2); my $level = length($prefix)/2-1; $levels[$level] = "$levels[$level-1]/$node"; print("$prefix$levels[$level]\n"); } __DATA__ |-- DIR_COLORS |-- X11 | |-- WindowMaker | | |-- WMGLOBAL | | `-- WindowMaker | |-- XF86Config | |-- Xresources | |-- Xsession | |-- app-defaults | | |-- Beforelight | | |-- Bitmap | | `-- Xvidtune | |-- glx.conf | |-- lbxproxy | | `-- AtomControl |-- xinetd.conf |-- xinetd.d | |-- cups-lpd | |-- cvs | |-- fam | |-- proftpd-xinetd | |-- rsync | `-- sshd-xinetd |-- xml | `-- catalog `-- xpdfrc
|-- ./DIR_COLORS |-- ./X11 | |-- ./X11/WindowMaker | | |-- ./X11/WindowMaker/WMGLOBAL | | `-- ./X11/WindowMaker/WindowMaker | |-- ./X11/XF86Config | |-- ./X11/Xresources | |-- ./X11/Xsession | |-- ./X11/app-defaults | | |-- ./X11/app-defaults/Beforelight | | |-- ./X11/app-defaults/Bitmap | | `-- ./X11/app-defaults/Xvidtune | |-- ./X11/glx.conf | |-- ./X11/lbxproxy | | `-- ./X11/lbxproxy/AtomControl |-- ./xinetd.conf |-- ./xinetd.d | |-- ./xinetd.d/cups-lpd | |-- ./xinetd.d/cvs | |-- ./xinetd.d/fam | |-- ./xinetd.d/proftpd-xinetd | |-- ./xinetd.d/rsync | `-- ./xinetd.d/sshd-xinetd |-- ./xml | `-- ./xml/catalog `-- ./xpdfrc

I would think
print("$levels[$level]\n");
would make more sense than
print("$prefix$levels[$level]\n");
but I gave you what you asked for.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (2)
As of 2023-09-30 22:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?