Advertisement
Online Test Banks
Score higher
See Online Test Banks
eLearning
Learning anything is easy
Browse Online Courses
Mobile Apps
Learning on the go
Explore Mobile Apps
Dummies Store
Shop for books and more
Start Shopping

The Most Useful File Tests in Perl

Part of the Perl For Dummies Cheat Sheet

Programming with Perl is fairly straightforward, which runs to the letters you use for file tests. For example, r tests whether a file can be read, and T looks for a text file. Here are most useful file tests in Perl:

Test Description
-e File exists.
-r File can be read.
-w File can be written to.
-z File is exactly zero bytes long.
-d Named item is a directory, not a file.
-T File is a text file. (The first chunk of a file is examined, and it’s a text file if fewer than 30 percent or so of the characters are nonprintable.)
-B File is a binary file. (This is the exact opposite of the -T test — it’s a binary file if more than 30 percent or so of the characters are nonprintable.)
-s Size of the file in bytes.
-C Creation age of file.
-A Access age of file.
-M Modification age of file.
  • Add a Comment
  • Print
  • Share
blog comments powered by Disqus
Advertisement
Advertisement

Inside Dummies.com

Dummies.com Sweepstakes

Win an iPad Mini. Enter to win now!