Richard Lee wrote: > What is the best way to indicate past hour from current time without > using a module? > > so if it's 12:00, then 11:00-12:00 > > if it's 17:30 then 16:30 to 17:30 > > if it's 00:30 then 23:30 to 00:30 > > I wrote a below program and works but there has to be a better and > easier(not sure if I want easier as I am trying to learn) but I want to > do it the right perl way(despite > perl's motto).. > > let me know please. > > #!/usr/bin/perl -w > use strict; > use diagnostics; > > my $time = localtime; > my @time_1 = split / /, $time; > my $start_time; > > for ($time_1[4]) { > if ($_ =~ /00:([0-5][0-9]:[^ ])/) { > $start_time = join(':', 23,$1); > } else { > /(.*):(.*):(.*)/; > $start_time = join(':', $1 - 1, $2,$3); > } > } > > print "$start_time to $time \n"; > > __END__ > Wed Apr 2 01:04:07 2008
Hi Richard. How about the program below. HTH, Rob use strict; use warnings; my $time = localtime; my $start_time; for ($time) { my $hms = (split)[3]; ($start_time = $hms) =~ s/(\d+)/($1 - 1) % 24/e; } print "$start_time to $time \n"; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/