Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

Perl | sleep() Function

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

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();

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();

Output:

Thu Mar 28 06:02:26 2019
Thu Mar 28 06:02:27 2019
My Personal Notes arrow_drop_up
Last Updated : 07 May, 2019
Like Article
Save Article
Similar Reads