File Test Operators 
Author Message
 File Test Operators

I want to check if the modification time of a file is older than 1 hour.
Is that code

 $mtime=((stat('file.ext'))[9]);
 if (time()-$mtime<3600) { ... }

equivalent to this one

 if (-M 'file.ext' < (1/24)) { ... }

And is there a way to print the return-value of "-M 'file.ext'"
or have I therefore to use stat?

Thx & GreetingX,
 Alex

Sent via Deja.com http://www.*-*-*.com/
Before you buy.



Mon, 09 Sep 2002 03:00:00 GMT  
 File Test Operators
I want to check if the modification time of a file is older than 1 hour.
Is that code
$mtime=((stat('file.ext'))[9]);
if (time()-$mtime<3600) { ... }
equivalent to this one
if (-M 'file.ext' < (1/24)) { ... }
And is there a way to print the return-value of "-M 'file.ext'"
or have I therefore to use stat?
Thx & GreetingX,
Alex

Sent via Deja.com http://www.deja.com/
Before you buy.



Mon, 09 Sep 2002 03:00:00 GMT  
 File Test Operators
I've got already a few answers via email, but no one hast posted
in here, so I'll do it.

The code-snippets are equivalent, but -M 'file.ext' is faster
and to save the value you can just use "$X=-M 'file.ext';".

Thanks for all the answers,
 Alex


Quote:

> I want to check if the modification time of a file is older than 1
hour.
> Is that code

> $mtime=((stat('file.ext'))[9]);
> if (time()-$mtime<3600) { ... }

> equivalent to this one

> if (-M 'file.ext' < (1/24)) { ... }

> And is there a way to print the return-value of "-M 'file.ext'"
> or have I therefore to use stat?

> Thx & GreetingX,
> Alex

> Sent via Deja.com http://www.deja.com/
> Before you buy.

Sent via Deja.com http://www.deja.com/
Before you buy.


Mon, 09 Sep 2002 03:00:00 GMT  
 File Test Operators


muenchen.de> says...

Quote:
> I want to check if the modification time of a file is older than 1 hour.
> Is that code

>  $mtime=((stat('file.ext'))[9]);
>  if (time()-$mtime<3600) { ... }

> equivalent to this one

>  if (-M 'file.ext' < (1/24)) { ... }

Almost equivalent.  '-M' is measured from when the program began to
execute (time $^T), but time() is the current time.  Unless the program
is long-running, there will be no difference.

Quote:
> And is there a way to print the return-value of "-M 'file.ext'"
> or have I therefore to use stat?

Huh?  The value of -M is a number.  Use it any way you wish.

--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/



Mon, 09 Sep 2002 03:00:00 GMT  
 File Test Operators
For whoever can affect this, I'd like to take this moment to point out
that it's pretty hard to find the documentation for the filetest
operators.  

   perldoc -q filetest

nothing

   perldoc perlop

search on "filetest".  first hit is right next to some text that says to
go look at perlfunc

   perldoc perlfunc

okay, here i am at last!  search on filetest.  Hits under readdir, stat,
maybe one other place.  But not near the actual documentation you want,
where it uses the phrase "file test".  Of course you can find it with a
search on "-M" or something, but it would be nice if we could just put the
word "filetest" in the section on the file test thingies so that people
who think that's what they're called (from seeing it expressed that way
everywhere else) can find it easily.  All this would take would be a
change from

       -X FILEHANDLE

       -X EXPR

       -X      A file test, where X is one of the letters listed
               below.  This unary operator takes one argument,

to

       -X FILEHANDLE

       -X EXPR

       -X      A file test, or, "filetest operator", where X is
               one of the letters listed below.  This unary
               operator takes one argument,

mike


Quote:

>I've got already a few answers via email, but no one hast posted
>in here, so I'll do it.

>The code-snippets are equivalent, but -M 'file.ext' is faster
>and to save the value you can just use "$X=-M 'file.ext';".

>Thanks for all the answers,
> Alex



>> I want to check if the modification time of a file is older than 1
>hour.
>> Is that code

>> $mtime=((stat('file.ext'))[9]);
>> if (time()-$mtime<3600) { ... }

>> equivalent to this one

>> if (-M 'file.ext' < (1/24)) { ... }

>> And is there a way to print the return-value of "-M 'file.ext'"
>> or have I therefore to use stat?

>> Thx & GreetingX,
>> Alex

>> Sent via Deja.com http://www.deja.com/
>> Before you buy.

>Sent via Deja.com http://www.deja.com/
>Before you buy.

--
Michael South, Head Mathophile, fulcrum.org


Wed, 11 Sep 2002 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. File test operators can't tell a file from a directory

2. File Test Operators and Speed

3. Wildcards allowed in file test operators?

4. help with file test operator

5. File test operator question

6. File Test Operators -B and -T

7. File test operators problem

8. -s file test operator failure

9. Where is -e (file test operator) in man?

10. Question about File test operators

11. Variable substitution with file test operators

12. file test operators

 

 
Powered by phpBB® Forum Software