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, how to link to one, and how to remove it. How do you copy a file?
A2: You could just open both the file to copy from and the file to copy to, and then read lines from one and print them to the other. Or you could use back-quotes to call the system copy command (as you'll learn on Day 18). Or you could use the File::Copy module, which gives you a copy function for copying files or file handles from a source to a destination.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset