perl-5.38.0
utime LIST

Changes the access and modification times on each file of a list of files. The first two elements of the list must be the NUMERIC access and modification times, in that order. Returns the number of files successfully changed. The inode change time of each file is set to the current time. For example, this code has the same effect as the Unix touch(1) command when the files already exist and belong to the user running the program:

ファイルのアクセス時刻と修正(modification) 時刻を変更します。 LIST の最初の二つの要素に、数値で表わしたアクセス時刻と修正時刻を 順に指定します。 変更に成功したファイルの数を返します。 各ファイルの inode 変更(change)時刻には、その時点の時刻が設定されます。 例えば、このコードはファイルが 既に存在して いて、ユーザーが 実行しているプログラムに従っているなら、 Unix の touch(1) コマンドと同じ効果があります。

    #!/usr/bin/perl
    my $atime = my $mtime = time;
    utime $atime, $mtime, @ARGV;

Since Perl 5.8.0, if the first two elements of the list are undef, the utime(2) syscall from your C library is called with a null second argument. On most systems, this will set the file's access and modification times to the current time (i.e., equivalent to the example above) and will work even on files you don't own provided you have write permission:

Perl 5.8.0 から、リストの最初の二つの要素が undef である 場合、C ライブラリの utime(2) システムコールを、秒の引数を null として 呼び出します。 ほとんどのシステムでは、これによってファイルのアクセス時刻と修正時刻を 現在の時刻にセットし(つまり、上記の例と等価です)、 書き込み権限があれば他のユーザーのファイルに対しても動作します。

    for my $file (@ARGV) {
        utime(undef, undef, $file)
            || warn "Couldn't touch $file: $!";
    }

Under NFS this will use the time of the NFS server, not the time of the local machine. If there is a time synchronization problem, the NFS server and local machine will have different times. The Unix touch(1) command will in fact normally use this form instead of the one shown in the first example.

NFS では、これはローカルマシンの時刻ではなく、NFS サーバーの時刻が 使われます。 時刻同期に問題がある場合、NFS サーバーとローカルマシンで違う時刻に なっている場合があります。 実際のところ、Unix の touch(1) コマンドは普通、最初の例ではなく、 この形を使います。

Passing only one of the first two elements as undef is equivalent to passing a 0 and will not have the effect described when both are undef. This also triggers an uninitialized warning.

最初の二つの要素のうち、一つだけに undef を渡すと、その 要素は 0 を渡すのと等価となり、上述の、両方に undef を 渡した時と同じ効果ではありません。 この場合は、未初期化の警告が出ます。

On systems that support futimes(2), you may pass filehandles among the files. On systems that don't support futimes(2), passing filehandles raises an exception. Filehandles must be passed as globs or glob references to be recognized; barewords are considered filenames.

futimes(2) に対応しているシステムでは、ファイルハンドルを引数として 渡せます。 futimes(2) に対応していないシステムでは、ファイルハンドルを渡すと 例外が発生します。 ファイルハンドルを認識させるためには、グロブまたはリファレンスとして 渡されなければなりません; 裸の単語はファイル名として扱われます。

Portability issues: "utime" in perlport.

移植性の問題: "utime" in perlport