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

Files and Filesystems

File path components are separated with / on Unix, with \ on Windows, and with : on Macs. Some systems support neither hard links (link) nor symbolic links (symlink, readlink, lstat). Some systems pay attention to capitalization of filenames, some don't, and some pay attention when creating files but not when reading them.

There are modules that can help. The standard File::Spec modules provide some functions of the Right Thing persuasion:

use File::Spec::Functions;
chdir( updir() );        # go up one directory
$file = catfile( curdir(), 'temp', 'file.txt' );

That last line reads in ./temp/file.txt on Unix and Windows, or :temp:file.txt on Macs, or [.temp]file.txt on VMS, and stores the file's contents in $file.

The File::Basename module, another platform-tolerant module bundled with Perl, splits a pathname into its components: the base filename, the full path to the directory, and the file suffix.

Here are some tips for writing portable file-manipulating Perl programs:

  • Don't use two files of the same name with different case, like test.pl and Test.pl, since some platforms ignore capitalization.

  • Constrain filenames to the 8.3 convention (eight-letter names and three-letter extensions) where possible. You can often get away with longer filenames as long as you make sure the filenames will remain unique when shoved through an 8.3-sized hole in the wall. (Hey, it's gotta be easier than shoving a camel through the eye of a needle.)

  • Minimize nonalphanumeric characters in filenames. ...

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