|
Posted by Ben Morrow on May 13, 2008, 7:01 pm
Please log in for more thread options
>
> If you create a new file, -M on that file will return a negative number.
> You have assigned to $MINUTES a positive number so the condition
>
> -M >= $MINUTES
>
> will never hold for any file created after the script has been started.
>
> Because of this logic error, I am a bit confused about what you really
> want. Assuming you mean what you say about files "older than one
> minute", you need to compare to current time not to -M.
>
> From perldoc perlvar:
>
> $BASETIME
> $^T The time at which the program began running, in seconds since
>
> So, to find the files older than 60 seconds, you would use the
> following:
>
<snip>
> my $mtime = -M;
> my $age = $^T - $mtime * SECONDS_PER_DAY ;
>
> if ( time - $age > 60 ) {
...or forget both -M and $^T (especially since converting a time to a
float and back probably isn't a good idea) and just use
use File::stat;
if (time - stat($_)->mtime <= 60)
Ben
--
I must not fear. Fear is the mind-killer. I will face my fear and
I will let it pass through me. When the fear is gone there will be
nothing. Only I will remain.
ben@morrow.me.uk Frank Herbert, 'Dune'
|