perl跑脚本自用简单模板

#!/user/bin/perl -w
# 2018.05.05
# 一般模板
#  scc
use POSIX;
use strict;
use Time::HiRes qw(gettimeofday tv_interval);


print "\n----------------------------------NEW ONE------------------------------------------";
# 输出运行当前时间
my $year_month_day = strftime("%Y%m%d %H:%M:%S",localtime());
print "\nstart now : '$year_month_day'"."\n";

# 开始运行前时间
my $now1=[gettimeofday];
#==============================运行代码========================
print "=================================================\n\n";
my $count = 0 ;
while( $count < 10000){
    $count += 1;
}

print  "now the count is :\t"."$count";
print "\n\n===============================================";
#=============================================================
# 结束运行时间
my $now2=[gettimeofday];
# 计算时间差
my $diff = tv_interval $now1,$now2;


# 输出时间差
if ($diff / 60 <1 ){       # 秒
    print "\nConsuming time:"."$diff"."\tseconds";
}elsif($diff / 60 <= 60 ){ # 分
    my $diffm = round($diff / 60, 2);
    print "\nConsuming time:"."$diffm"."\tminutes";
}else{                     # 时
    my $diffm = round($diff / 60 /60, 2);
    print "\nConsuming time:"."$diffm"."\thours";
}

# 输出运行全部结束当前时间
my $finished = strftime("%Y%m%d %H:%M:%S",localtime());
print "\nFINISHED : '$year_month_day'";
print "\n------------------------------------------------------------------------------------";

bat 文件:
perl 1.pl >>now.log;

脚本输出结果:
脚本运行结果

猜你喜欢

转载自blog.csdn.net/scc_hy/article/details/80208540