项目时间比较紧急,不会perl,恳请个位高手解释一段程序!
#!/usr/bin/perl
$WMC_SYSTEM_NAME = $ARGV[0];
$old_file_name = "";
$curr_file_name = "";
while( true ) {
$now = time(); ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) = localtime($now);
$curr_file_name = "/u06/wmc/systems.old/".$WMC_SYSTEM_NAME."/0110".sprintf("%02d",$mday).".log";
if( $old_file_name eq $curr_file_name ) {
sleep(60);
}
else {
open( LOG_FILE, $curr_file_name );
while( $line=<LOG_FILE> ) {
last if( $line =~ /\xBE/ ); # SOH: Start of header
}
do {
$index = index( $line, "\xBE" );
if( $index>0 ) {
print substr( $line, 0, $index );
print "\n";
}
$mediation_time = hex(substr( $line, $index+1, 8 ));
($m_sec,$m_min,$m_hour,$m_mday,$m_mon,$m_year,$m_wday,$m_yday) = localtime($mediation_time);
# Wait until the alarm occurs
$now = time();
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) = localtime($now);
$def_sec = ($m_hour-$hour)*3600+($m_min-$min)*60+($m_sec-$sec);
if( $def_sec>0 ) {
sleep( $def_sec );
}
while( true ) {
$line = <LOG_FILE>;
last if( $line =~ /\xBE/ ); # Next SOH
last if( eof(LOG_FILE) );
chop( $line );
print $line."\n";
# See if now is already another day.
$now = time(); ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) = localtime($now);
$new_file_name = "/u06/wmc/systems.old/".$WMC_SYSTEM_NAME."/0110".sprintf("%02d",$mday).".log";
last if not ( $new_file_name eq $curr_file_name );
}
# See if now is already another day.
$now = time(); ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) = localtime($now);
$new_file_name = "/u06/wmc/systems.old/".$WMC_SYSTEM_NAME."/0110".sprintf("%02d",$mday).".log";
last if not( $new_file_name eq $curr_file_name );
} while( !eof(LOG_FILE) );
close( LOG_FILE );
$old_file_name = $curr_file_name;
}
}
我只知道这段程序是按照日期读取log文件,问题是他是怎么读的?是一次全部读取还是怎么样的,中间的def_sec是什么意思呢(在程序中)