Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/clojure/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
perl-打开文件-获取日期_Perl - Fatal编程技术网

perl-打开文件-获取日期

perl-打开文件-获取日期,perl,Perl,有没有一种更有效的方法来获取perl中的日期,而且我已经看到了不同格式的open语句——这是打开文件的可接受的方法吗 06:27:54 /data/noc/startup/startup_ptf_pats.sh startup initiated by waljoh @ Tue Nov 1 06:27:54 EDT 2011 06:27:54 /data/noc/startup/startup_ptf_pats.sh verifying that engine is change c

有没有一种更有效的方法来获取perl中的日期,而且我已经看到了不同格式的open语句——这是打开文件的可接受的方法吗

06:27:54 /data/noc/startup/startup_ptf_pats.sh startup initiated by waljoh @ Tue Nov  1      06:27:54 EDT 2011
06:27:54 /data/noc/startup/startup_ptf_pats.sh verifying that engine is change controlled
06:27:54 /data/noc/startup/check_change_controlled_files.sh all change controlled commands files are in synch
06:27:54 /data/noc/startup/check_today_is_holiday.sh Today is NOT a holiday
06:27:54 /data/noc/startup/check_ntpq.sh 159.79.35.42 time offset (0) is below 100   
这是我写的剧本:

#!/usr/bin/perl
use warnings;
use strict;

my $todays_date = `/bin/date +%m-%d-%y`;
chomp $todays_date ;

my $grabDIR = "/data/noc/startup/logs/";
my $grabFILE = "pats." . "$todays_date" . ".txt";

print "$grabDIR$grabFILE\n" ;

my FILE;
open (FILE, "more $grabDIR$grabFILE | ");
while (<FILE>) {
        my $line = $_;
        print $line; 
        sleep 1;
}
#/usr/bin/perl
使用警告;
严格使用;
my$todays_date=`/bin/date+%m-%d-%y`;
吃$todays\u date;
my$grabDIR=“/data/noc/startup/logs/”;
我的$grabbile=“pats.”。“$todays\u date”。“.txt”;
打印“$grabDIR$grabFILE\n”;
我的档案;
打开(文件“more$grabDIR$grabbile |”);
而(){
我的$line=$\ux;
打印$行;
睡眠1;
}
关于日期:

use POSIX ();
my $todays_date = POSIX::strftime( '%m-%d-%Y', localtime );
open的最佳实践是三参数open——无需
更多

open( my $fh, '<', "$grabDIR$grabFILE" ) 
    or die "Could not open $grabDIR$grabFILE! - $!"
    ;
打开(my$fh),截止日期:

use POSIX ();
my $todays_date = POSIX::strftime( '%m-%d-%Y', localtime );
open的最佳实践是三参数open——无需
更多

open( my $fh, '<', "$grabDIR$grabFILE" ) 
    or die "Could not open $grabDIR$grabFILE! - $!"
    ;

open(my$fh),不要使用外部命令(例如“date”和“more”)来执行Perl本质上可以执行的操作。如前所述,您可以使用POSIX模块的strftime()来格式化从服务器的localtime获取的时间戳

对于open(),请使用三参数形式:

open (FILE, '<', $grabDIR$grabFILE) or die "Can't open $grabDIR$grabFILE: $!\n";

open(文件,不要使用外部命令(例如“date”和“more”)来执行Perl本身可以执行的操作。如前所述,您可以使用POSIX模块的strftime()来格式化从服务器的localtime获取的时间戳

对于open(),请使用三参数形式:

open (FILE, '<', $grabDIR$grabFILE) or die "Can't open $grabDIR$grabFILE: $!\n";

open(FILE,'呃,是的。不要这样做。而且……您可能还想了解如何实际打开和读取文件。您的代码示例在“我的文件”上有一个致命错误行。我想你不是要本地化一个裸文件句柄。呃,是的。不要这样做。而且……你可能还想阅读如何实际打开和读取文件。你的代码示例在“我的文件”行上有一个致命错误。我想你不是要本地化一个裸文件句柄。