Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Looking at the output you're getting, it seems like File::DirWalk is doing its traversal in such a way that the deeper paths are listed first, and assuming that will always be the case, then Enlil's suggestion should work fine.

There's another way, which would not be dependent on the assumption that the original listing will always be ordered like that, but it involves post-processing after the DirWalk thing is done:

@folder = sort @folder; my $npaths = scalar @folder; push @folder, "~~~"; @folder = grep /./, map { (index($folder[$_+1], "$folder[$_]\\") == 0) ? '' : $f +older[$_] } ( 0..$npaths );

That is, sort the array and eliminate an element if it is fully contained as an initial substring of the next element. (The standard string sort will always put "a1" before "a1\1".)

Note that I added a bogus element on the array, to avoid an "undefined value" warning when map reaches the last directory. It's not elegant, alas...


In reply to Re: Array Normalization of File::DirWalk by graff
in thread Array Normalization of File::DirWalk by Samy_rio

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (8)
As of 2024-04-25 15:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found