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.
perl
Perl
Syntax: sleep(seconds) Returns: seconds passed to it as parameter, on successExample 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:
Example 2:
Thu Mar 28 06:02:21 2019 Thu Mar 28 06:02:26 2019
#!/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