Perl Programming Page 5 - Perl: Appending and Writing to Files |
There are also ways to test if a file is read, writable, or executable: $my_file="superhero.txt"; if (-r $my_file) { #whatever you want to occur if the file is readable } $my_file="superhero.txt"; if (-w $my_file) { #whatever you want to occur if the file is writable } $my_file="superhero.txt"; if (-x $my_file) { #whatever you want to occur if the file is executable } And lastly, if you want to test more than one you can use the OR (||), and AND (&&) (ow my brains!) operators. $my_file="superhero.txt"; if ( (-e $my_file) && (-w $my_file) ) { #whatever you want to occur if the file exists and is writable } Here is a table for a quick reference:
All right folks. That's it for this section covering Files. In the next series we will cover how to work with Directories and possibly forms, time permitting. So swing by often. Till then...
blog comments powered by Disqus |
|
|
|
|
|
|
|