- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How does “do something OR DIE()†work in Perl?
The die() function can be used to stop the script and can be used to display a message to the end user. It can be used at the right side of the OR ( || ) operator and at left side can be any expression like the eval() function.
Case 1 − Using die() function with no parameter
![die() Function no Parameter](https://www.tutorialspoint.com/assets/questions/media/13982/die()_ function_no_parameter.jpg)
The following is the output.
![die() function Output](https://www.tutorialspoint.com/assets/questions/media/13982/die()_ function_no_parameter_output.jpg)
Now we can use $! to print the error number and a message to the user in the die() function.
Case 2 − Use of $! in the die() function
![$ die() Function](https://www.tutorialspoint.com/assets/questions/media/13982/$die()_ function.jpg)
The following is the output.
![$ die() function Output](https://www.tutorialspoint.com/assets/questions/media/13982/$die()_ function_output.jpg)
Case 3 − Display some message to the end user with the die() function
![die() Function](https://www.tutorialspoint.com/assets/questions/media/13982/die()_ function.jpg)
The following is the output.
![die() function Output](https://www.tutorialspoint.com/assets/questions/media/13982/die()_ function_output.jpg)
Advertisements