-2

以下にサンプルスクリプトの「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);
        }
    }
}
4

1 に答える 1

2

間違った比較演算子を選択しました。

eqおよびgt文字列比較演算子です。整数を返すためstat、整数比較を使用する必要があります。

eqする必要があります==

gtする必要があります>

于 2009-12-22T02:51:59.813 に答える