1nickt has asked for the wisdom of the Perl Monks concerning the following question:
Greetings all,
I need to walk up the directory tree from where I am until I find a directory containing a certain marker file. (This is to locate the base directory of an installation, which is then used to add the project's /lib to @INC.)
Is there anything more elegant than this?
(I am aware that this does not handle the file not being found.)use strict; use warnings; use Path::Tiny; sub find_base { -f "$_[0]/.marker" ? $_[0] : find_base($_[0]->parent) +} my $base = find_base( path(__FILE__)->realpath->parent ); unshift @INC, "$base/lib"; use Some::Class; ...
Thanks for any suggestions!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Recursively walk up a directory tree
by tybalt89 (Monsignor) on Feb 10, 2018 at 16:17 UTC | |
by 1nickt (Canon) on Feb 10, 2018 at 19:37 UTC | |
by tybalt89 (Monsignor) on Feb 10, 2018 at 22:21 UTC | |
by AnomalousMonk (Archbishop) on Feb 10, 2018 at 22:29 UTC | |
|
Re: Recursively walk up a directory tree
by choroba (Cardinal) on Feb 10, 2018 at 22:41 UTC | |
by 1nickt (Canon) on Feb 11, 2018 at 01:51 UTC | |
by Your Mother (Archbishop) on Feb 11, 2018 at 00:05 UTC | |
|
Re: Recursively walk up a directory tree
by Anonymous Monk on Feb 10, 2018 at 16:46 UTC | |
by stevieb (Canon) on Feb 10, 2018 at 17:31 UTC | |
by Anonymous Monk on Feb 10, 2018 at 17:41 UTC | |
by Your Mother (Archbishop) on Feb 10, 2018 at 20:33 UTC | |
| |
by 1nickt (Canon) on Feb 10, 2018 at 18:24 UTC | |
by Anonymous Monk on Feb 11, 2018 at 08:20 UTC | |
| |
by stevieb (Canon) on Feb 10, 2018 at 17:44 UTC |