以下にサンプルスクリプトの「stat」の使用法をいくつか見つけました。
$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?
}
ありがとうございました。
[更新0]
たとえば、以下のスタイル。スクリプトにデバッグするとき。script_ltime 値と dest_file_mtime 値が等しくないことがわかりました。
if ($script_ltime eq $dest_file_mtime ) // eq used
{
printf "No $this_file Scan Needed\n";
exit(0);
}
ところで、スタイル belwo のスクリプトの代わりに i の場合。スクリプトを変更しても見つかりました。スクリプトはまだ再スキャンされません。dest_file_mtime の値は常に source_mtime の値より大きくなります。
if ($dest_file_mtime gt $source_mtime) // gt used
{
printf "No $this_file Scan Needed\n";
exit(0);
}
だから私は eq OR gt を使うのを混乱させました。また、「3 つのファイルのうちの 1 つを変更すると、スクリプトは常に必要なスキャンを実行する」にはどのスタイルが適していますか。
【更新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);
}
}
}