FindBin::Parents(3)

NAME
FindBin::Parents - List parent dirs of the given path from curr to root.

SYNOPSIS
    use FindBin::Parents qw( dir_paths );

    # on *NIX (incl. OSX)
    # '/foo/bar/bim/bam' yields
    # /foo/bar/bim/bam
    # /foo/bar/bim
    # /foo/bar
    # /foo
    #
    # on VMS
    # 'Bletch$Blort:[foo.bar.bim.bam]' yields
    # Bletch$Blort:[foo.bar.bim.bam]
    # Bletch$Blort:[foo.bar.bim]
    # Bletch$Blort:[foo.bar]
    # Bletch$Blort:[foo]
    #
    # on MSW
    # 'z:/foo/bar/bim/bam' yields
    # z:/foo/bar/bim/bam
    # z:/foo/bar/bim
    # z:/foo/bar
    # z:/foo
    #
    # $path is first passed through rel2abs and canonpath
    # which should yield clean, absolute paths.
    #
    # note that the return vlaue is context-sensitive:

    my $array_ref   = dir_paths $path;
    my @array       = dir_paths $path;

    # for any non-directory /foo/bar/bletch/blort, the final
    # 'blort' is dropped and the paths leading to it are returned:

    dir_paths $0;

    # /foo/bar/bletch   # parent dir of blort
    # /foo/bar
    # /foo

    # Note: non-existant paths are processed, but may require
    # an extra assume-dir argument to treat the argument as a
    # directory (or not, no way to tell unless it exists, eh?).
    #
    # the default is true, these are equivalent:

    my @found
    = dir_paths '/foo/bar/bletch/blort/non-existent';

    my @found
    = dir_paths '/foo/bar/bletch/blort/non-existent', 1;

    # /foo/bar/bletch/blort/non-existant
    # /foo/bar/bletch/blort
    # /foo/bar/bletch
    # /foo/bar/bletch
    # /foo/bar
    # /foo

    # false value drops the last entry:

    my @found
    = dir_paths '/foo/bar/bletch/blort/non-existant', 0;

    # /foo/bar/bletch/blort
    # /foo/bar/bletch
    # /foo/bar/bletch
    # /foo/bar
    # /foo