1 #!/usr/bin/perl -w
2 # File: appendfiles.pl
3 # Author: Tom Large - tlarge@thelug.org
4 # Location: http://www.thelug.org/docs/
5 # Description: Convert hh:mm:ss or hh:mm into number of seconds
6 # since midnight
7
8 print " Enter Time HH:mm:ss -> ";
9 $_ = <STDIN>;
10 $hour = 100;
11 $min = 100;
12 $sec = 0;
13 if(/^(\d+):(\d+)$/ )
14 {
15 $hour = $1;
16 $min = $2;
17 $sec = 0;
18 }
19 elsif( /^(\d+):(\d+):(\d+)$/ )
20 {
21 $hour = $1;
22 $min = $2;
23 $sec = $3;
24 }
25
26 if (($hour < 24) && ($min < 60) && ($sec < 60))
27 {
28 $spm = $hour*3600 + $min*60 + $sec;
29 print "Time $_ \n SPM $spm\n";
30 }
31 else
32 {
33 print "Please enter the time in HH:mm:ss or HH:mm format.\n";
34 }
syntax highlighted by Code2HTML, v. 0.9.1