in reply to RFC: TCP Client/Server development as windows service (ActiveState PerlSVC) tutorial
Thanks for the writeup! Just a quick nitpick on a side issue:
sub doPad { my ($val, $len) = @_; while(length($val) < $len) { $val = "0$val"; } return $val; } sub getDateTime { my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localti +me(time()); return doPad($mday,2) . "-" . doPad($mon+1,2). "-" . ($year + 1900) . " " . doPad($hour,2) . ":" . doPad($min, 2) . ":" . doPad($sec, 2) . "\n"; }
Personally, I would've used sprintf() for the formatting/zero-padding.
sub getDateTime { my ($sec,$min,$hour,$mday,$mon,$year) = localtime(time()); return sprintf "%02d-%02d-%d %02d:%02d:%02d\n", $mday, $mon+1, $year+1900, $hour, $min, $sec; }
Or even (if loading the POSIX module isn't an issue):
use POSIX (); sub getDateTime { return POSIX::strftime("%d-%m-%Y %H:%M:%S\n", localtime(time) ); }
Doesn't make better dates, though — just a little more compact :)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: RFC: TCP Client/Server development as windows service (ActiveState PerlSVC) tutorial
by cavac (Prior) on Dec 22, 2011 at 15:30 UTC |