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.


In reply to Re: reparse tree in textfile by ikegami
in thread reparse tree in textfile by myuserid7

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.