Cari di Perl 
    Perl User Manual
Daftar Isi
(Sebelumnya) Remove one link to a fileOptional trailing block in a w ... (Berikutnya)
Functions for filehandles, files, or directories

Set a file's last access and modify times

Daftar Isi

  • utime LIST

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

    1. #!/usr/bin/perl
    2. $atime = $mtime = time;
    3. utime $atime, $mtime, @ARGV;

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

    1. for $file (@ARGV) {
    2. utime(undef, undef, $file)
    3. || warn "couldn't touch $file: $!";
    4. }

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

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

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

    Portability issues: utime in perlport.

 
Source : perldoc.perl.org - Official documentation for the Perl programming language
Site maintained by Jon Allen (JJ)     See the project page for more details
Documentation maintained by the Perl 5 Porters
(Sebelumnya) Remove one link to a fileOptional trailing block in a w ... (Berikutnya)