Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^3: tree command

by RichardK (Parson)
on Oct 13, 2015 at 14:56 UTC ( [id://1144713]=note: print w/replies, xml ) Need Help??


in reply to Re^2: tree command
in thread tree command

No, you can know the length of the list and still only process it once. The two things aren't related at all.

Replies are listed 'Best First'.
Re^4: tree command
by Skeeve (Parson) on Oct 14, 2015 at 06:21 UTC

    Okay. So would you mind telling me how I could filter out:

    • hidden files and directories (okay - "glob")
    • files

    without iterating over the content of the directory and know in advance that the last 3 items in my list don't count?

    Example: I have in my list [ a b c d e ] where b, d and e are files, which I do not want to display, while a and c are the directories to show. How would I know that in advance?

    With my approach I filter b, d and e out, leaving me with just [ a c ]. So I know that after "c" there won't be any more files or directories to be displayed.

    How would you achieve this?


    s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
    +.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e
      You can use
      my @dirs = glob '*/';

      To get the number of files, just subtract the number of dirs from the number of everything.

      لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

        Which will iterate of the files a second time and will access the file system while I iterate over an array. Or am I wrong?


        s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
        +.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e

      Doesn't the code I posted do exactly that with only one pass? I didn't add the display file bit, but that's trivial to add if you need it.

      Here's the output of my code run on my junk directory, it seems to do what you ask :)

      +-dbf +-palindrome +-plot +-rules | +-abc1 | | +-ba | | +-de | | +-te

        if you didn't just post a part of the output, my tree would look like this:

        . \--dbf |--palindrome |--plot \--rules \--abc1 |--ba |--de \--te

        You see? I need to know, when I'm at "dbf", "rules", "abc1" and "te", that this one is the last element in the respective directory to stop printing the superfluous "|" characters you have.


        s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
        +.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2024-04-20 00:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found