Reputation: 1027
Could anyone show me an example of how to pause for one second in Perl? I am trying the sleep command and it isn't working.
Upvotes: 4
Views: 48854
Reputation: 2187
This is the direct answer, which I provide just in case there was some problem with the asker's original code.
#!/usr/bin/perl
print "Hello World.\n";
sleep 1;
Upvotes: 2
Reputation: 1259
Why you guys, that's obviously not the way.
select undef, undef, undef, 1;
Upvotes: 3
Reputation: 169038
sleep(1)
will do exactly that. If it's "not working" then you are measuring something incorrectly. (That or you're not passing the right arguments -- showing us your code would be helpful.)
$ time perl -e 'sleep(1)' real 0m1.003s user 0m0.000s sys 0m0.004s
Upvotes: 14
Reputation: 943625
#!/usr/bin/perl
use strict;
use warnings;
use diagnostics;
$| = 1; # Disable output buffering
for (1..10) {
print '.';
sleep 1;
}
print "\n";
Upvotes: 16