Skip to Main Content
Programming Perl, 3rd Edition
book

Programming Perl, 3rd Edition

by Larry Wall, Tom Christiansen, Jon Orwant
July 2000
Intermediate to advanced content levelIntermediate to advanced
1104 pages
35h 1m
English
O'Reilly Media, Inc.
Content preview from Programming Perl, 3rd Edition

Cwd

use Cwd;
$dir = getcwd();    # Where am I?

use Cwd 'chdir';
chdir "/tmp";       # Updates $ENV{PWD}.

use Cwd 'realpath';
print realpath("/usr////spool//mqueue/../");  # prints /var/spool

The Cwd module provides platform-independent functions to determine your process's current working directory. This is better than shelling out to pwd (1) because non-POSIX-conforming systems aren't guaranteed to have such a command, and Perl runs on more than just POSIX platforms. The getcwd function, which is exported by default, returns the current working directory using whatever mechanism is deemed safest on the current platform. If you import the chdir function, it overrides the built-in operator with the module's operator, which maintains the $ENV{PWD} environment variable; commands you might launch later that would care about that variable would then have a consistent view of their world. The realpath function resolves its pathname argument of any symbolic links and relative-path components to return a full path directory in canonical form, just like realpath (3).

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mastering Perl, 2nd Edition

Mastering Perl, 2nd Edition

brian d foy
Programming the Perl DBI

Programming the Perl DBI

Tim Bunce, Alligator Descartes
Perl in a Nutshell, 2nd Edition

Perl in a Nutshell, 2nd Edition

Nathan Patwardhan, Ellen Siever, Stephen Spainhour

Publisher Resources

ISBN: 0596000278Supplemental ContentErrata