SORU
4 ŞUBAT 2009, ÇARŞAMBA


Nasıl bir dosya al'son perl'de kez değiştirilmiş s?

Bir filehandle $fh yoktur sanırım. -e $fh -s $fh a slew of additional information about the file ile dosya boyutu ile varlığını kontrol edebilirsiniz. Nasıl son değiştirilen zaman damgası alabilir miyim?

CEVAP
4 ŞUBAT 2009, ÇARŞAMBA


Yerleşik File::stat (Perl 5.004 itibariyle dahil) modülünü kullanabilirsiniz.

stat($fh) döner dosya tanıtıcı ile ilgili şu bilgi geçti (perlfunc man page for stat) ile bir dizi görüşme:

  0 dev      device number of filesystem
  1 ino      inode number
  2 mode     file mode  (type and permissions)
  3 nlink    number of (hard) links to the file
  4 uid      numeric user ID of file's owner
  5 gid      numeric group ID of file's owner
  6 rdev     the device identifier (special files only)
  7 size     total size of file, in bytes
  8 atime    last access time since the epoch
  9 mtime    last modify time since the epoch
 10 ctime    inode change time (NOT creation time!) since the epoch
 11 blksize  preferred block size for file system I/O
 12 blocks   actual number of blocks allocated

Bu dizinin 9 öğe döneminden beri son değişiklik zamanı takip eder00:00 1 Ocak 1970 GMT). Bu yerel saat belirleyebilirsiniz:

my $epoch_timestamp = (stat($fh))[9];
my $timestamp       = localtime($epoch_timestamp);

Bu önlemek içinsihirli sayı9 önceki örnekte, ayrıca gerekli Time::localtime, başka bir yerleşik modül (Perl 5.004 itibariyle dahil) kullanın. Bu (belki) daha okunaklı bazı kod gerektirir:

use File::stat;
use Time::localtime;
my $timestamp = ctime(stat($fh)->mtime);

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • DanceOn

    DanceOn

    6 Mayıs 2006
  • Elly Awesome

    Elly Awesome

    15 ŞUBAT 2010
  • Myron and Nejusha dance

    Myron and Ne

    2 AĞUSTOS 2012

İLGİLİ SORU / CEVAPLAR