Lone Shepherd
Lone Shepherd

Reputation: 1005

How to get file last modified time with Perl 5.004 and no modules

I have a standalone version of Perl for Windows (5.004) that does not include any modules. I want to run a script to check the last modified time of several files.

I could use File::qstat, but that module doesn't exist (the copy of Perl is in version control, so it can be used by people who do not have ActivePerl or Strawberry Perl installed).

It seems like there are three options:

  1. Figure out how to put a newer, more functional, standalone Perl installation into version control
  2. Just add the File::Stat module somehow, and do use lib (does that work on 5.004?)
  3. Use some built-in functions included in 5.004 for Windows to get the file status.

How can I do this?

Upvotes: 0

Views: 1063

Answers (2)

JRFerguson
JRFerguson

Reputation: 7516

perl -le '$file=shift or die;print scalar localtime((stat($file))[9])' file

See stat .

Upvotes: 4

Jonathan Leffler
Jonathan Leffler

Reputation: 753950

Why on earth are you stuck using Perl 5.004? I have source from Perl 5.5.3 dated in 1999, so Perl 5.004 is likely to be several years older than that. (I found source for Perl 5.004_04 after all; the latest timestamp in that was 1997-10-15 06:46.) So, that's about 15 years old.

The stat function is likely to exist and do the job you need.

Upvotes: 1

Related Questions