我在下面找到了一些示例腳本「stat」用法。如何比較Perl統計信息返回的mtimes?
$source_mtime = (stat($source_file))[9];
$dest_file_mtime = (stat($dest_file))[9];
$script_mtime = (stat($this_file))[9];
if (-e $dest_xml_file)
{
if ($dest_file_mtime gt $source_mtime) // gt used
{
printf "No $this_file Scan Needed\n";
exit(0);
}
# OR the style below
if ($script_ltime eq $dest_file_mtime) // eq used
{
printf "No $this_file Scan Needed\n";
exit(0);
}
# OR the style below
if ($script_ltime eq $source_mtime) // eq used
{
printf "No $this_file Scan Needed\n";
exit(0);
}
# or other style?
}
謝謝。
[updated 0]
eg eg below style。當我調試到腳本。我發現script_ltime值和dest_file_mtime值不會是平等的。
if ($script_ltime eq $dest_file_mtime) // eq used
{
printf "No $this_file Scan Needed\n";
exit(0);
}
順便說一句,如果我而不是腳本與風格貝沃。我發現即使我修改了我的腳本。腳本仍然不會再次掃描。對於dest_file_mtime值,始終大於source_mtime值。
if ($dest_file_mtime gt $source_mtime) // gt used
{
printf "No $this_file Scan Needed\n";
exit(0);
}
爲什麼我不知道使用eq或gt。以及哪種風格更適合「當我更改三個文件中的一個時,腳本將始終掃描所需內容。」
[更新1]
if (-e $dest_file) {
open(DEST_FILE, "$dest_file") ;
$_ = <DEST_FILE>;
close DEST_FILE;
if (/^\/\*([\w]+)\/\/([\w]+)\*\//) { # ignored by me code here
$ltime = $1; # middle variable value assignment
$script_ltime = $2;
if (($ltime eq $mtime) && # eq operator is meaningful
($script_ltime eq $script_mtime)) {
printf "No $this_file Scan Needed\n";
exit(0);
}
}
}
你有什麼問題嗎? – 2009-12-22 02:04:36
這取決於你想要比較的東西。換句話說,你需要知道你想要做什麼,然後才能知道你將如何去做。 – 2009-12-22 02:13:50
@Alexandr。以上更新。謝謝。 – 2009-12-22 02:16:05