Click here to get back home

infinite loop to monitor directories

 HomeNewsGroups | Search | About
 comp.lang.perl.misc    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
infinite loop to monitor directories mr.vlad.dracula 05-13-2008
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'

Similar ThreadsPosted
can't get out of infinite while loop August 17, 2007, 4:14 pm
infinite loop (newbie) March 8, 2005, 2:52 pm
MIME::Tools infinite loop June 20, 2005, 7:18 am
infinite loop when perl is trying to print warning November 22, 2007, 10:29 am
Getting all directories/files from current directory and using -d flag for the directories October 8, 2004, 2:05 pm
Extracting Directories and Sub Directories and Counting November 1, 2004, 9:48 pm
LWP::UserAgent infinite hang March 5, 2007, 6:18 pm
log monitor September 14, 2006, 10:04 am
How to monitor changes in a directory November 9, 2006, 5:13 pm
monitor for sleeping processes December 23, 2004, 10:03 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap