Thomas Bätzler wrote:
Richard Lee <[EMAIL PROTECTED]> asked:
What is the best way to indicate past hour from current time
without using a module?
[...]
#!/usr/bin/perl -w
use strict;
printf "%d:%02d to %d:%02d\n", (localtime time - 3600 )[2,1], (localtime
time)[2,1];
__END__
my $time = localtime;
my @time_1 = split / /, $time;
Don't use a variable name like $time, it'll introduce hard to
find bugs in your code should you ever forget the sigil $.
Also splitting scalar localtime for hours and minutes is
redundant. If you want individual values instead of a time
stamp, use localtime in scalar context, i.e.
my @time_1 = localtime;
Once you know that
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime;
you can pick out individual values like this:
my( $min, $hour ) = ( localtime )[1,2];
or even
my( $hour, $min ) = ( localtime )[2,1];
HTH,
Thomas
really like this.
thanks.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/