/ Published in: Perl
Use this to add up your overtime. May not be suited for processing untrusted input (e.g. as a CGI script), as the input check is rather rudimentary.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
#!/usr/bin/perl use strict; print <<EOF; Welcome to tc.pl, the time calculator. Expressions may contain hour:minute:second or minute:second literals. Use socat (http://www.dest-unreach.org/socat/) to add readline capability: socat READLINE EXEC:./tc.pl,pty EOF while( <> ) { s/\s+//g; next if /^$/; if( /([^0-9+\-*\/:.()])/ ) { next; } s/([0-9]+):([0-9]+):([0-9]+)/(3600*$1+60*$2+$3)/g; s/([0-9]+):([0-9]+)/(60*$1+$2)/g; # prevent interpretation as octal: s/\b0+([1-9][0-9]*)\b/$1/g; $secs -= $mins*60; $mins -= $hours*60; }