exit() function evaluates the expression passed to it and exits from the Perl interpreter while returning the value as the exit value. The exit() function does not always exit immediately but calls the end routines before it terminates the program. If no expression is passed to the exit function then a default value 0 is returned. Use of exit() function is limited and should not be used to exit from a subroutine. To exit from a subroutine, die or return is used.
Parameter: value which is to be returned on function call
Returns: the value passed to it or 0 if function is called without an argument
Here is how the above code works
Step 1: Get a bid value from the user.
Step 2: Exit returns bid value if the bid is less than 1000 and terminates the program.
Step 3: Prints this message if the bid is greater than or equal to 1000.
Passing Parameter to exit function
A parameter can be passed to the exit function that gets stored in the system’s variable.
Note: Value passed to the exit function can be any random value, it needs not to be any specific value.
The example below shows how to pass a value to the exit function:
Here is how the above program works:-
Step 1: Opening a file in read mode.
Step 2: When it is unable to open a file, if block executes, that calls an exit function and passes an error code value 56 to the system.
Step 3: If opening the file is successful then it returns 1.
In order to view the values returned by an exit function on Linux/Unix $? is used. The command echo $? is executed on the terminal in order to view the value returned by an exit function.
- Perl | Basic Syntax of a Perl Program
- Perl Tutorial - Learn Perl With Examples
- Measuring script execution time in PHP
- What purpose does a <script> tag serve inside of a <noscript> tag?
- Perl vs C/C++
- Perl | le operator
- Perl | gt operator
- Perl | oct() Function
- Perl | next operator
- Perl | log() Function
- Perl | cmp Operator
- Perl | chr() Function
- Perl | last in loop
- Perl | exp Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.