in reply to Find config file by traverse directory

use File::Spec qw(); use Path::Class qw(dir file); use File::HomeDir qw(); sub find_config { my $path = dir('.')->absolute; while ($path) { my $file = file($path, 'my.conf'); return $file if -e $file; last if $path eq File::Spec->rootdir; $path = $path->parent; } my $file = file(File::HomeDir->my_home, 'my.conf'); return -e $file ? $file : ''; }

Replies are listed 'Best First'.
Re^2: Find config file by traverse directory
by Anonymous Monk on Apr 26, 2012 at 11:53 UTC

    on windows root doesn't include the drive letter

    So , since you're using absolute, you should  last if $path eq $path->parent;