G
Guest
I couldn't find the solution to this on google, so... There must be
some way to write two simple functions to convert a single digit date
to a two digit date and strip the ":" characters from time.
Thanks in advance,
Walter
#!perl
$today=`date`;
($weekday, $month, $day, $time, $junk) = split(' ', $today, 5);
$daynum = DayToNum( $day );
$timenum = TimeToNum( $time );
## 1 -> 01
print "\$daynum\( $day \) = $daynum \n";
## 12:16:56 -> 121656
print "\$timenum\( $time \) = $timenum \n";
sub DayToNum {
## doesn't work
if ( length lt 2 ) { $_ = "0" . "$_"; }
## doesn't work
# if (/^1$/) { return "01"; }
# elsif (/^2$/) { return "02"; }
# elsif (/^3$/) { return "03"; }
# elsif (/^4$/) { return "04"; }
# elsif (/^5$/) { return "05"; }
# elsif (/^6$/) { return "06"; }
# elsif (/^7$/) { return "07"; }
# elsif (/^8$/) { return "08"; }
# elsif (/^9$/) { return "09"; }
# else { return "$_"; }
}
sub TimeToNum {
## doesn't work
s/://g;
## doesn't work
# $_ =~ s/://g;
## works...
# $timenum = $time;
# $timenum=~ s/://g;
}
some way to write two simple functions to convert a single digit date
to a two digit date and strip the ":" characters from time.
Thanks in advance,
Walter
#!perl
$today=`date`;
($weekday, $month, $day, $time, $junk) = split(' ', $today, 5);
$daynum = DayToNum( $day );
$timenum = TimeToNum( $time );
## 1 -> 01
print "\$daynum\( $day \) = $daynum \n";
## 12:16:56 -> 121656
print "\$timenum\( $time \) = $timenum \n";
sub DayToNum {
## doesn't work
if ( length lt 2 ) { $_ = "0" . "$_"; }
## doesn't work
# if (/^1$/) { return "01"; }
# elsif (/^2$/) { return "02"; }
# elsif (/^3$/) { return "03"; }
# elsif (/^4$/) { return "04"; }
# elsif (/^5$/) { return "05"; }
# elsif (/^6$/) { return "06"; }
# elsif (/^7$/) { return "07"; }
# elsif (/^8$/) { return "08"; }
# elsif (/^9$/) { return "09"; }
# else { return "$_"; }
}
sub TimeToNum {
## doesn't work
s/://g;
## doesn't work
# $_ =~ s/://g;
## works...
# $timenum = $time;
# $timenum=~ s/://g;
}