Stephen Gran on 18 Oct 2003 14:21:41 -0400


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: newer of two files


On Sat, Oct 18, 2003 at 01:48:36PM -0400, Jeff Abrahamson said:
> Silly question, I think:
> 
>     I have two files, $file1 and $file2. I want to say
> 
>         if($file1 is newer than $file2) {
>             do something
>         }
> 
> I'm sort of embarrassed by this question, but the point is just that I
> kind of recall there being a one-line way of doing this with file
> tests or something, and I'm not finding it.
> 
> I know how to do it with two explicit stat calls and then comparing
> mtime's.

I think that

if ( -M $file1 < -M$file2 ) {
    do something;
}

is what you're looking for.  I could be wrong, as I frequently am.

-- 
 --------------------------------------------------------------------------
|  Stephen Gran                  | The debate rages on: Is PL/I Bachtrian  |
|  steve@lobefin.net             | or Dromedary?                           |
|  http://www.lobefin.net/~steve |                                         |
 --------------------------------------------------------------------------

Attachment: signature.asc
Description: Digital signature