From: M on
Is there an easy way to get perl to return the mtime of the oldest file in a
directory?

M


From: Abigail on
_
M (no(a)spam.tonsjunkmail.com) wrote on VCLXXXVII September MCMXCIII in
<URL:news:13jk6m2gka8l223(a)corp.supernews.com>:
|| Is there an easy way to get perl to return the mtime of the oldest file in a
|| directory?


No.


Reason #1 is that "oldest file" isn't clearly defined. Reason #2 is that
for some definitions of "oldest", including the very obvious one, you need
a piece of information that many filesystems don't keep track of.

None of these reasons have anything to do with the language you try to
solve the problem with.


Abigail
--
$_ = "\nrekcaH lreP rehtona tsuJ"; my $chop; $chop = sub {print chop; $chop};
$chop -> () -> () -> () -> () -> () -> () -> () -> () -> () -> () -> () -> ()
-> () -> () -> () -> () -> () -> () -> () -> () -> () -> () -> () -> () -> ()
From: Steven M. O'Neill on
Abigail <abigail(a)abigail.be> wrote:
> _
>M (no(a)spam.tonsjunkmail.com) wrote on VCLXXXVII September MCMXCIII in
><URL:news:13jk6m2gka8l223(a)corp.supernews.com>:
>|| Is there an easy way to get perl to return the mtime of the oldest file in a
>|| directory?
>
>
>No.
>
>Reason #1 is that "oldest file" isn't clearly defined. Reason #2 is that
>for some definitions of "oldest", including the very obvious one, you need
>a piece of information that many filesystems don't keep track of.
>
>None of these reasons have anything to do with the language you try to
>solve the problem with.

http://groups.google.com/group/comp.unix.shell/msg/777922ad16818eec?dmode=source&hl=en

--
Steven O'Neill steveo(a)panix.com
Brooklyn, NY http://www.panix.com/~steveo
From: Joost Diepenmaat on
On Tue, 13 Nov 2007 15:44:35 -0600, M wrote:

> Is there an easy way to get perl to return the mtime of the oldest file
> in a directory?
>
> M

Depends on what you call the oldest file. Many file systems don't have a
concept of oldest file (for IMHO good reasons, regardless of Abigail's
comments).

see "perldoc -f readdir" and "perldoc -f -X" (especially -M and -C).

Also, looking for inode in your favorite Unix manual (or google) may be
helpful.

Joost.


From: Abigail on
_
Steven M. O'Neill (steveo(a)panix.com) wrote on VCLXXXVII September
MCMXCIII in <URL:news:fhd74l$lls$1(a)reader1.panix.com>:
%% Abigail <abigail(a)abigail.be> wrote:
%% > _
%% >M (no(a)spam.tonsjunkmail.com) wrote on VCLXXXVII September MCMXCIII in
%% ><URL:news:13jk6m2gka8l223(a)corp.supernews.com>:
%% >|| Is there an easy way to get perl to return the mtime of the oldest file in a
%% >|| directory?
%% >
%% >
%% >No.
%% >
%% >Reason #1 is that "oldest file" isn't clearly defined. Reason #2 is that
%% >for some definitions of "oldest", including the very obvious one, you need
%% >a piece of information that many filesystems don't keep track of.
%% >
%% >None of these reasons have anything to do with the language you try to
%% >solve the problem with.
%%
%% http://groups.google.com/group/comp.unix.shell/msg/777922ad16818eec?dmode=source&hl=en
%%


I saved the program Tom wrote, and saved it in "/tmp/tom".
Then I ran the following program:

#!/usr/bin/perl

use strict;
use warnings;
no warnings 'syntax';

my $DIR = "/tmp/test";
die "$DIR already exists\n" if -f $DIR;
mkdir $DIR, 0755 or die "mkdir: $!";
open my $fh1 => ">", "$DIR/oldest" or die "open: $!";
print $fh1 "Hello\n";
close $fh1 or die "close $!";
sleep 10;
open my $fh2 => ">", "$DIR/newest" or die "open: $!";
print $fh2 "Hello\n";
close $fh2 or die "close $!";
sleep 10;
open my $fh3 => ">>", "$DIR/oldest" or die "open: $!";
print $fh3 "world\n";
close $fh3 or die "close: $!";

system perl => "/tmp/tom", $DIR;

system rm => '-r', $DIR;

__END__


Its output:

oldest file in /tmp/test is /tmp/test/newest, time is Wed Nov 14 12:22:53 2007


Hmmm, /tmp/test/oldest was created before /tmp/test/newest, so, arguebly,
it's the oldest file in the directory.
But Tom's program didn't return it's mtime; it returned the mtime of the
newest file.


Getting the mtime of a file is easy. Getting the mtimes of all the files
in a directory is easy as well, and selecting the oldest mtime from the
set is trivial as well.


But what is the "oldest" file? The first one created? The last one modified?
The first entry in the directory? Determining what "oldest" stands for,
that's the hard part of the original question.



Abigail
--
use lib sub {($\) = split /\./ => pop; print $"};
eval "use Just" || eval "use another" || eval "use Perl" || eval "use Hacker";