Perl | sleep() Function
sleep() function in Perl is an inbuilt function which is used to delay the execution of the current script for a specified number of seconds or forever if parameter is not specified. The sleep( ) function accepts seconds as a parameter and returns the same on success.
Syntax: sleep(seconds)
Returns: seconds passed to it as parameter, on success
Example 1:
#!/usr/bin/perl -w # Using localtime() function # to print the time print scalar localtime (); # calling the sleep function sleep (5); print "\n" ; print scalar localtime (); |
chevron_right
filter_none
Output:
Thu Mar 28 06:02:21 2019 Thu Mar 28 06:02:26 2019
Example 2:
#!/usr/bin/perl -w # Using localtime() function # to print the time print scalar localtime (); # Using rand() to generate random delay sleep ( rand (7)); print "\n" ; print scalar localtime (); |
chevron_right
filter_none
Output:
Thu Mar 28 06:02:26 2019 Thu Mar 28 06:02:27 2019
Recommended Posts:
- Perl | cos() Function
- Perl | tell() Function
- Perl | int() function
- Perl | chr() Function
- Perl | abs() function
- Perl | sin() Function
- Perl | log() Function
- Perl | uc() Function
- Perl | oct() Function
- Perl | exp Function
- Perl | hex Function
- Perl | each() Function
- Perl | ord() Function
- Perl | rindex() Function
- Perl | chop() 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 contribute@geeksforgeeks.org. 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.