add half an hour to all times in file

D

Dan Jacobson

$ cat file
18:25
18:56
$ perl -wlpe 'Please tell me what to write here to get the following' file
18:55
19:26
Maybe perldoc Date::parse has something to do with this.
In Unix I can do $ date +%H:%M -d '22:22 + 30 minutes'.
 
T

Tore Aursand

Maybe perldoc Date::parse has something to do with this.

Indeed. What went wrong when you tried to use it?


--
Tore Aursand <[email protected]>

"You know the world is going crazy when the best rapper is white, the best
golfer is black, France is accusing US of arrogance and Germany doesn't
want to go to war."
 
F

Frank Maas

Dan Jacobson said:
$ cat file
18:25
18:56
$ perl -wlpe 'Please tell me what to write here to get the following' file
18:55
19:26

perl -wlpe 'my ($h,$m)=split(/:/); my $t=($h*60)+$m+30; $h=int($t/60)%24;
$m=$t%60; $_=sprintf "%02d:%02d",$h,$m;'

--Frank
 
J

John W. Krahn

Dan said:
$ cat file
18:25
18:56
$ perl -wlpe 'Please tell me what to write here to get the following' file
18:55
19:26
Maybe perldoc Date::parse has something to do with this.
In Unix I can do $ date +%H:%M -d '22:22 + 30 minutes'.


$ perl -e'
use Time::Local;
my @times = qw/ 18:25 18:56 23:42 /;
for my $time ( @times ) {
print "$time ";
$time = join":",(gmtime(timegm(0,(reverse $time=~/\d+/g),(gmtime)[3,4,5])+1800))[2,1];
print "$time\n";
}
'
18:25 18:55
18:56 19:26
23:42 0:12



John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top