From the course: Perl 5 Essential Training
Unlock the full course today
Join today to access over 22,500 courses taught by industry experts or purchase this course individually.
File test operators - Perl Tutorial
From the course: Perl 5 Essential Training
File test operators
- [Voiceover] Perl provides a large number of file test operators. These are used for testing the status of an object in the file system, like a file. For example, here I'm using the -e operator to see if a file exists. Down here on line nine, you see there's an if statement and in the if statement I have -e and a file name. So -e is the file test operator that tests if a file exists. The file test operator takes one argument: it can be a file name, a file handle, or a directory handle. We'll cover handles when we cover file IO later on in the course, but if I go ahead and run this, without opening the file or anything like that, it just checks the file system to see if the file exists. If it does, it returns true, as in this case it does. If I change this file name to a file name that doesn't exist and I go ahead and I run that, you'll notice my result is No such file or directory. That's the error given in the special error variable, $! If the file test returns false, it checks to…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.