From the course: Perl 5 Essential Training

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

The system error variable

The system error variable - Perl Tutorial

From the course: Perl 5 Essential Training

Start my 1-month free trial

The system error variable

- [Voiceover] Perl provides a special variable that contains the current value of the operating system's global error condition. Here is a working copy of errno.pl from chapter seven of the exercise files. And you'll notice that there is a "filename", "notfound.txt", and in our folder over here we do not have that file. And I test to see if that file exists with the "file exists" operator, and we'll talk more about these operators later on in this course. And if it's found, it says "found", if not, it says "error" and displays the error message with the dollar exclamation point. That's the special variable that contains the value of that global error number. And in this case, because we're using it in a string context, it'll display the error string. So when I run this, it says "error: No such file or directory", which is the standard error message for trying to find a file that does not exist. Now, this special errno value is available in both numeric and string form. So, if instead…

Contents