1. Perl
  2. builtin functions
  3. here

sleep function - sleeps for a specified amount of time

You can use the sleep function to sleep for a specified amount of time. Sleep means stopping a program without using CPU resources.

# Sleep for 10 seconds
sleep 10;

Sleep in microseconds

The sleep function can only sleep in seconds. To sleep in seconds less than that, use the usleep function of Time::Hires module. The seconds you specify are microseconds. Microseconds are "1/1000" of "1/1000" of 1 second.

use Time::HiRes 'usleep';

# 300 microseconds sleep

Example program

This is an example program of the sleep function. After displaying "Hello", sleep for 3 seconds and display "World".

use strict;
use warnings;

print "Hello\n";
print "World\n";

Related Informatrion