[comp.unix.questions] solution in Perl

merlyn@intelob.intel.com (Randal L. Schwartz @ Stonehenge) (05/11/89)

In article <207@psgdc>, rg@psgdc (Dick Gill) writes:
[wants code to get readable modtime from filename]
| I'll be happy to get a C program, shellscript or anything else
| that I can call from a Bourne shell script.

Ok, be happy.  Here's a very brief Perl program to do what you want:
################################################## snip snip
#!/usr/bin/perl
@s = stat($ARGV[0]);
@t = localtime($s[9]);
printf "%04d/%02d/%02d %02d:%02d:%02d\n",
	1900+$t[5], 1+$t[4], $t[3], $t[2], $t[1], $t[0];
################################################## snip snip
What?  You don't have Perl?  You'll probably have to write a small
C program that does the above as: (1) take the argument, (2) fstat it,
(3) look at the "mtime" field, (4) run it through "localtime",
and (5) print the result.

Or get Perl.  (Yeay, Larry!)

Just a Perl hacker,
-- 
***** PLEASE NOTE THE NEW ADDRESS *****
/=Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095===\
{ on contract to BiiN, Hillsboro, Oregon, USA, until 14 May 1989     }
{ <merlyn@intelob.intel.com> ...!uunet!tektronix!biin!merlyn         }
{ or try <merlyn@agora.hf.intel.com> after 15 May 1989               }
\=Cute quote: "Welcome to Oregon... home of the California Raisins!"=/