rikhardo has asked for the wisdom of the Perl Monks concerning the following question:

Helo, i have a file with a computer dir tree. and i need to create the full path to each end-file. Whats the ves way to do it? recursive function? do anyone have a sugestion? thanks.

Replies are listed 'Best First'.
Re: recursive function
by jellisii2 (Hermit) on May 20, 2014 at 15:01 UTC
Re: recursive function
by davido (Cardinal) on May 20, 2014 at 16:28 UTC

    I would prefer if you had spent as much time refining the specification within the question you're asking as we're likely to expend answering your question. As it is written, your question is vague enough as to garner multiple interpretations. Possibly one of us will get lucky, answering the question you intended to ask. But in the process, several of us will answer questions we thought you asked, which may completely miss the vague intent of the question.

    My guess is that you have, as you said, a file that contains a directory tree... which I will assume means a list of paths. Each path must include a file name, since you said "full path to each end-file." So what you might have is this:

    /foo/bar/baz.txt /foo/bingo/cantaloupe/commotion.json /bar/diamonds.dconf ...and so on...

    Where these actual files come from, I don't understand, but I am going to go with the guess that you need to create paths, and possibly populate them with files that you might be copying from somewhere.

    For full path creation, without the need to build paths piece by piece, look at File::Path, which has a make_path function. This function can create a full path all in one shot.

    For copying files into those paths, there's File::Copy. Both File::Copy and File::Path are core Perl modules, so you have no good reason (outside of "for educational purposes") to not use them.

    There is a non-core module which may also be helpful if you're willing to pull modules from CPAN (which you should be willing and able to do): File::Copy::Recursive.

    Turning one or more of these modules into a full solution is left as an exercise for the reader, who must know a lot more about his question than we do. ;)


    Dave

Re: recursive function
by wjw (Priest) on May 20, 2014 at 14:47 UTC

    When you say 'tree', does that imply something like the 'tree' command output

    Something like:

    Root |_next_to_root |_next_to_next_to_root ....

    Along those lines? Just a little clarification please... :-)

    UPDATEAssuming above is about right... Took a moment to see what search might bring up...

    Here is one result. Scroll down just a bit...

    Hope that is helpful...

    ...the majority is always wrong, and always the last to know about it...

    Insanity: Doing the same thing over and over again and expecting different results...

Re: recursive function
by Laurent_R (Canon) on May 20, 2014 at 18:38 UTC

    As it is written, your question is vague enough as to garner multiple interpretations. Possibly one of us will get lucky, answering the question you intended to ask. But in the process, several of us will answer questions we thought you asked, which may completely miss the vague intent of the question.

    davido is making a very valid point, and the best understanding I could make of your question is not the same at all as davido's. Please explain better what you want.