dolphin wrote:
Hi,

Hello,

I want to use perl and print time before and after sleep but not
successful, can anyone advice?

#!/usr/bin/perl

my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime
time;
my $timenow="$hour$min$sec";
print "It is now $timenow\n";
sleep 15;
my $timelater="$hour$min$sec";
print "It is now $timelater\n";

Why the value of timelater is the same as timenow after sleep 15? How
to print the value of time after sleep for 15?

When you assign values to variables they retain those values until you change them, so:

#!/usr/bin/perl
use warnings;
use strict;

my ( $sec, $min, $hour ) = localtime;
my $timenow = "$hour:$min:$sec";
print "It is now $timenow\n";
sleep 15;
( $sec, $min, $hour ) = localtime;
my $timelater = "$hour:$min:$sec";
print "It is now $timelater\n";




John
--
The programmer is fighting against the two most
destructive forces in the universe: entropy and
human stupidity.               -- Damian Conway

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to