fast_abs_path#
Canonicalise a path strictly: resolve symlinks and ./.., or return undef if any component is missing.
Synopsis#
use Cwd qw(fast_abs_path);
my $abs = fast_abs_path($path);
my $abs = fast_abs_path(); # defaults to current directory
What you get back#
A plain Perl string with the absolute, symlink-free path, or
undef if any part of the path cannot be resolved (including
the leaf). Unlike abs_path, there is no parent-plus-leaf
fallback — a missing final component is treated as an error.
Examples#
Verify that a path exists and get its canonical form in one step:
use Cwd qw(fast_abs_path);
my $abs = fast_abs_path('/etc/passwd');
defined $abs or die "not found: $!";
print $abs, "\n"; # /etc/passwd
Reject non-existent files up front:
use Cwd qw(fast_abs_path);
print defined fast_abs_path('/no/such/file') ? "ok" : "missing";
# missing
Resolve the current directory quickly:
use Cwd qw(fast_abs_path);
print fast_abs_path(), "\n"; # equivalent to getcwd()
Edge cases#
Empty string or no argument — treated as
..Any missing component (including the leaf) — returns
undef. Useabs_pathwhen a missing leaf should still produce a path.Symlink loop — returns
undefand sets$!toELOOP.
Differences from upstream#
Upstream’s
fast_abs_pathlocalises$ENV{PWD},chdirs into the target, and reads the new CWD back. pperl callscanonicalize(3)directly — the result is the same, but the process working directory is never disturbed, so concurrent code that observes CWD sees no perturbation.
See also#
abs_path— same resolution, with a parent-plus-leaf fallbackrealpath— POSIX-style alias forabs_pathgetcwd— absolute path of the current directory only