Skip to content

Instantly share code, notes, and snippets.

@axtstar
Created July 12, 2017 12:25
Show Gist options
  • Save axtstar/6356a6867858b238667cc36f1997bb87 to your computer and use it in GitHub Desktop.
Save axtstar/6356a6867858b238667cc36f1997bb87 to your computer and use it in GitHub Desktop.
exchange time(00:00 expression) to number(minutes)
use strict;
use warnings;
my $timeStr = "";
my $length = @ARGV;
if ($length>0){
$timeStr = $ARGV[0];
}
else {
$timeStr = <STDIN>;
}
if ($timeStr =~ /([0-9]+):([0-9]+):([0-9]+)/){
my $var ="$1" * 60 * 60 + "$2" * 60 + "$3";
print "$var";
} elsif ($timeStr =~ /([0-9]+):([0-9]+)/){
my $var ="$1" * 60 + "$2";
print "$var";
}
@axtstar
Copy link
Author

axtstar commented Jul 12, 2017

ex:

perl timeToNum.pl 06:08:10

you get the number 22090

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment