From the course: Perl 5 Essential Training

Unlock the full course today

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

The die() function

The die() function - Perl Tutorial

From the course: Perl 5 Essential Training

Start my 1-month free trial

The die() function

- The die function will display an error message and then immediately exit the script. This is convenient for handling error conditions. Here's a working copy of hello.pl from chapter 13 of the Exercise Files. And just for illustration purposes, I'm going to create a variable called condition and assign it a true value, which, in this case, is the integer value one. And then, I'm going to test that condition. And if the condition is true, it will say condition true. And if it is not true, we'll say condition is false. Now, when I run this, of course it says true. And if I change this one to a zero and run it, it'll say false. Now, let's say that this is a really fatal error, and I don't want this to just end. Here, let me go ahead down here and put in a print statement, after conditional. So, we can see that when I run this, it still continues after the conditional. But if I put in die instead of say, couple of things happen. When I run this, you'll notice that it does not print after…

Contents