我是Perl的新手。任何人都可以解释它在线下的含义吗?
if ( -s $errorlog ) {
open( LOG, "$errorlog" ) or die "Unable to open logfile:$!\n";
while (<LOG>) {
my ($line) = $_;
chomp($line);
if ( $line =~ m/\d\d-\d\d \d\d:\d\d:\d\d ERROR / )
非常感谢您的回复。
答案 0 :(得分:6)
测试文件是否为空。
if (-s $filename) {
# The file is not empty
}
更多细节:
## if the file is not empty
if ( -s $errorlog ) {
## Open the file and assign the reference to variable LOG
## in case of failure, stop the program -- die
## with error message "Unable to open logfile:<FILE NAME>\n"
open( LOG, "$errorlog" ) or die "Unable to open logfile:$!\n";
## While not end of file
while (<LOG>) {
## read next line into local variable `line`
my ($line) = $_;
## remove clutter from it (http://perldoc.perl.org/functions/chomp.html)
chomp($line);
## if the line looks like "11-05 01:01:12 ERROR"
## Regular expression used, probably to test for a date
## after which string `ERROR` follows
if ( $line =~ m/\d\d-\d\d \d\d:\d\d:\d\d ERROR / )