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

Cwd

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

Provides current working directory operations.

Synopsis

use Cwd;
my $dir = cwd();
use Cwd 'abs_path';
my $abs = abs_path('relative/path');
my $abs = abs_path('/symlinked/../path');

Perl Equivalent

Cwd

Functions

abs_path

Returns the canonicalized absolute pathname of the argument. Resolves symlinks. Returns undef if the path cannot be resolved. If no argument is given, resolves the current directory.

use Cwd 'abs_path';
my $abs = abs_path('relative/path');
my $abs = abs_path();   # current directory

chdir

Changes the working directory and updates $ENV{PWD}. Unlike CORE::chdir, does NOT default to $ENV{HOME} when called without arguments. Returns 1 on success, 0 on failure.

use Cwd 'chdir';
chdir('/tmp') or die "Cannot chdir: $!";

cwd

Returns the current working directory as a string. All four names are synonyms in PetaPerl (no distinction between XS and pure-Perl implementations).

use Cwd;
my $dir = cwd();

fast_abs_path

Returns the canonicalized absolute pathname of the argument. Resolves symlinks. Returns undef if the path cannot be resolved. If no argument is given, resolves the current directory.

use Cwd 'abs_path';
my $abs = abs_path('relative/path');
my $abs = abs_path();   # current directory

fastcwd

Returns the current working directory as a string. All four names are synonyms in PetaPerl (no distinction between XS and pure-Perl implementations).

use Cwd;
my $dir = cwd();

fastgetcwd

Returns the current working directory as a string. All four names are synonyms in PetaPerl (no distinction between XS and pure-Perl implementations).

use Cwd;
my $dir = cwd();

getcwd

Returns the current working directory as a string. All four names are synonyms in PetaPerl (no distinction between XS and pure-Perl implementations).

use Cwd;
my $dir = cwd();

realpath

Returns the canonicalized absolute pathname of the argument. Resolves symlinks. Returns undef if the path cannot be resolved. If no argument is given, resolves the current directory.

use Cwd 'abs_path';
my $abs = abs_path('relative/path');
my $abs = abs_path();   # current directory