Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

File::Basename

Native Rust implementation built into the interpreter. Runtime: PP. See original documentation for the full Perl reference.

Provides path parsing functions: basename, dirname, fileparse.

Synopsis

use File::Basename qw(basename dirname fileparse);
my $base = basename("/usr/local/bin/perl");   # "perl"
my $dir  = dirname("/usr/local/bin/perl");    # "/usr/local/bin"
my ($name, $path, $suffix) = fileparse(
    "/usr/local/lib/libperl.so", qr/\.[^.]*/
);
# $name="libperl", $path="/usr/local/lib/", $suffix=".so"

Functions

basename

Returns the last component of a path, optionally removing a suffix. Trailing slashes are removed before extracting the last component.

See also: dirname, fileparse

dirname

Returns the directory portion of a path. Returns "." if the path contains no directory component.

See also: basename, fileparse

fileparse

Splits a path into (name, directory, suffix). This is the underlying function for basename and dirname. Suffixes can be strings or regex patterns.

See also: basename, dirname

fileparse_set_fstype

Set the filesystem type for path parsing. Always returns “Unix”; the argument is accepted but ignored.

Synopsis

use File::Basename 'fileparse_set_fstype';
fileparse_set_fstype('Unix');