Perl-4 Windows批处理(cmdbat)常用命令大全 2020-12-20

Perl-4 Windows批处理(cmdbat)常用命令大全 2020-12-20,第1张

你的$start_time是time()返回的时刻值吧,这个值是系统时间与某个时间之间的秒数,里面的946656000也是这种意义的一个时刻值吧,两个时刻之差就是时间差,86400=243600就是一天的时间,%86400表示时间差的一天内的时间数。

perl -e 'print scalar(localtime(time - 86400)), "\n"'

linux下date --date='yesterday'这个ok,不知道你在solaris的bash下能不能用

perl命令行参数怎么捕获? perl 获取命令行参数方法,以在windows *** 作系统为例,当我们在命令行中调用PERL程序的时候,我们往往会跟随一些参数,比如输入文件名,和输出文件名之类的信息。这些信息PERL会将它们存储在@ARGV数组中(和C语言一样)。比如在cmd中输入如下命令:

pppl -opcamfile opcamfileini -rcfile rcfiletxt -swapfile swapfiletmp -outfile outfiletxt

PERL会建立一个数组@ARGV=qw/-opcamfile opcamfileini -rcfile rcfiletxt -swapfile swapfiletmp -outfile outfiletxt/;然后我们想把这些信息做何用出就对应的处理数组,从数组中分离我们想要的数据就可以了。如下面的代码所示。shift的默认参数是@ARGV。

while ($#ARGV > -1) {

if ($ARGV[0] =~ /-opcamfile/i){

if ($ARGV[1] !~ /-/) {

$opcamfile = $ARGV[1];

shift;

}

shift;

} elsif ($ARGV[0] =~ /-rcfile/i) {

if ($ARGV[1] !~ /-/) {

$rcfile = $ARGV[1];

shift;

}

shift;

} elsif ($ARGV[0] =~ /-swapfile/i) {

if ($ARGV[1] !~ /-/) {

$swapfile = $AR GV[1];

shift;

}

shift;

} elsif ($ARGV[0] =~ /-outfile/i) {

if ($ARGV[1] !~ /-/) {

$outfile = $ARGV[1];

$outfile =~ s/_sim//g;

shift;

}

shift;

} else {

die 'Unrecognized argument, Exiting';

}

}

#!usr/bin/perl

use strict;

my $datachar;

if(!defined($ARGV[0]))

{

$datachar = "20110229";

#print "$datachar\n";

}

else{

$datachar = $ARGV[0];

#print "$datachar\n";

}

my $_=$datachar;

my $count =s/(-)/$1/ig, "\n";# i是不区分大小写 g是替换全部,统计字符串-字符的个数

my $position1 = index($datachar,"-",1);#4

my $position2 = index($datachar,"-",5);#7

my $len=length($datachar);

my @data;

my $year;

my $month;

my $day;

my @m=('01','02','03','04','05','06','07','08','09','10','11','12');

my @m1=('01','03','05','07','08','10','12');

my @m2=('04','06','09','11');

my @m3=('02');

#print "$len";

if($datachar =~/-/ and $len == 10 and $count == 2 and $position1 == 4 and $position2 == 7)

{ if ($datachar =~ m/[^0-9\-]/) #判断字符包含非数字但-字符除外

{print "10个字符的日期值不正确";

exit;} else {

#print "1\n";

@data=split(/-/,$datachar);

$year =$data[0];

$month=$data[1];

$day =$data[2];

#print "$year\n";

}

}elsif($datachar !~/-/ and $len == 8)

{ if ($datachar =~ m/[^0-9]/) #判断字符是否包含非数字字符

{print "8个字符的日期值不正确\n";

exit;} else {

#print "2\n";

$year =substr($datachar,0,4);

$month=substr($datachar,4,2);

$day =substr($datachar,6,2);

#print "$year\n";

#print "$month\n";

#print "$day\n";

}

}else {

print "$datachar 日期值不正确";

exit;

}

if (grep ({$month == $_ } @m))#判断值是否在数组中

{

#print "月份值正确";

}else {

print "月份值不正确\n";

exit;

}

if (grep ({$month == $_ } @m1) and ($day >'31' or $day<'01'))

{

print "大月份天值不正确\n";

exit;

}elsif (grep ({$month == $_ } @m2) and ($day >'30' or $day<'01'))

{

print "小月份天值不正确\n";

exit;

}elsif (grep ({$month == $_ } @m3) and (($year%4 == 0 and $year%100 != 0) or $year%400 == 0) and ($day>'29' or $day<'01'))

{

print "闰年2月份的天数值不正确\n";

exit;

}

elsif (grep ({$month == $_ } @m3) and ($day>'28' or $day<'01'))

{

print "平年2月份的天数值不正确\n";

exit;

}else

{

print "$datachar is right\n";

}

windows系统,保存脚本名apl,若不输入参数,默认值是20110229,运行apl。也可以输入一个参数运行,apl 2015101。如果你想批量检查文本文件中的参数,相信楼主的能力可以加上一个循环。

以上就是关于Perl-4 Windows批处理(cmd/bat)常用命令大全 2020-12-20全部的内容,包括:Perl-4 Windows批处理(cmd/bat)常用命令大全 2020-12-20、有一个很好的介绍Perl程序吗、perl编程: my $start_date = $start_time-($start_time-946656000)%86400; 为什么日期要如此计算等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/10163510.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-05
下一篇2023-05-05

发表评论

登录后才能评论

评论列表(0条)

    保存