Q&A

Q1: I'm on Unix. I was testing a script that reads from a file, and then deletes it. Because I didn't want it to actually delete the file until I was done debugging the script, I removed write permission from the file. But Perl went ahead and deleted it anyhow. Why?
A1: Setting the permissions on a file determines whether you can read or write the contents of that file. The filename—and whether that file can be renamed, moved, or changed—is controlled by the permissions of the enclosing directory. To actually prevent Perl from deleting files, remove write permission from the directory the file is in. Or, even better, comment out your unlink command until you've got the rest of the script debugged.
Q2:You've described how to rename a file, ...

Get Sams Teach Yourself Perl in 21 Days, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.