O'Reilly logo

Sams Teach Yourself Perl in 21 Days, Second Edition by Rafe Colburn, Laura Lemay

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Managing Files

In addition to simply reading from and writing to files, you can also manage them from inside Perl, just as you might from a command line or in a file manager: you can rename them, delete them, change their permissions, or create links to them. Each of these tasks makes use of several Perl built-in functions. In this section, you get an overview of each of these.

Renaming Files

To rename a file from one name to another, keeping its contents intact, use the rename function with two arguments: the old name of the file and the new name:

rename myfile, myfile.bak;

If a file with the same name as the new file already exists, Perl will overwrite it. If you're used to Unix, this won't be a problem. If you're a Windows or Mac user, beware! ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required