in reply to Re^2: Recursively walk up a directory tree
in thread Recursively walk up a directory tree

I believe you actually meant "distribution" if I've understood what you meant correctly. Semantics, I know, but an important distinction.

Hehe,

OP posts some code and asks Is there anything more elegant than this?

Yeah, its called a module.

Instead of doing ... 20 lines to modify global variable ... do use HideTwentyLines; and

elegance achieved

Replies are listed 'Best First'.
Re^4: Recursively walk up a directory tree
by Your Mother (Archbishop) on Feb 10, 2018 at 20:33 UTC

    Hidden and elegant are not synonymous. The @INC manipulation was a solid clue, as 1nickt confirmed, that modules might be a poor suggestion; especially wrapped in snark empty of discussion, caveat, or example. There is little less elegant, proper, or convincing than–

    a title

    –as a punchline. Unless it's The Aristocrats! of course.

    A reply falls below the community's threshold of quality. You may see it by logging in.
Re^4: Recursively walk up a directory tree
by 1nickt (Canon) on Feb 10, 2018 at 18:24 UTC

    Yeah, its called a module.

    Given that the purpose of finding the base directory is to be able to add the lib directory to @INC, how do you suggest such a module could be loaded?


    The way forward always starts with a minimal test.

        In some simple cases using:

        use FindBin '$RealBin'; use lib "$RealBin/../../../lib"; # or whatever
        is acceptable, even if completely inelegant. But usually it's a mistake since it means you can't move your test or script to another level in the tree without breaking it. As projects expand you often do move sub-directories around. The relative path also has to be different for different sub-directory levels, so it requires thought and maintenance even before you move anything. Hence the search for something better.

        Update: I was not familiar with tye's File::FindLib. It seems like it would be useful for "clean" well-designed projects. Unfortunately many projects are not clean or well-organized, having evolved sometimes over years and many different development teams. In some cases there are lib/ sub-directories off non-root directories (eg <base>/t/lib/, and using use File::FindLib 'lib'; from a test file like <base>/t/foo/bar.t will find the first (wrong) one. (This is what led to the use of a marker file).


        The way forward always starts with a minimal test.
Re^4: Recursively walk up a directory tree
by stevieb (Canon) on Feb 10, 2018 at 17:44 UTC

    Ok, I did misunderstand. I thought you were referring to packaging the code into a distribution :)