Re: 'file changed'-event
- From: "Veli-Pekka Tätilä" <vtatila@xxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 29 Dec 2005 12:48:56 +0200
Anno Siegel wrote:
> Michael Goerz <news2132@xxxxxxxxxxxxxxx> wrote in comp.lang.perl.misc:
>> I'm trying to execute a sub whenever a certain file on the disk changes.
>> Currently, I'm doing this with an infinite loop <snip>
>> Can I implement this with an event-based approach
> Unless your file system supports events you'll ultimately have to watch
> the file.
Michael,
You didn't mention your operating system in the post. If you happen to be
running Windows, might the Win32::ChangeNotify module be of help? It can be
found at:
http://search.cpan.org/~gsar/libwin32-0.191/ChangeNotify/ChangeNotify.pm
It is also available via ppm using the Active State repositories. Ano's
comment about having to poll manually unless the OS supports events got me
curious. Is the Win32 API function used by this module merely some syntactic
sugar to abstract away ugly polling code? Or alternatively, does the file
system support a true publish-subscribe model, that is events?
> file system's resolution is one second, so you should only stat the file
> once a second. If you don't need maximum resolution make the intervals as
> long as reasonable.
Well said. I mean, I've used similar polling tacs for the clipboard before
as the WaitForChange method has never worked for me properly. Sleeping at
least a second is of great help in terms of performance and llengthning the
interval is a compromise between responsivness and CPU or file system usage
as you pointed out. I guess this applies broadly to a large variety of
poling.
--
With kind regards Veli-Pekka Tätilä (vtatila@xxxxxxxxxxxxxxxxxxxx)
Accessibility, game music, synthesizers and programming:
http://www.student.oulu.fi/~vtatila/
.
- Follow-Ups:
- Re: 'file changed'-event
- From: David Serrano (Hue-Bond)
- Re: 'file changed'-event
- References:
- 'file changed'-event
- From: Michael Goerz
- Re: 'file changed'-event
- From: Anno Siegel
- 'file changed'-event
- Prev by Date: Re: My Regexp XML Parser -> Structured Perl Data, Cut & Paste Version, No Module's (Vol I)
- Next by Date: Re: installing perl and some modules on many hosts
- Previous by thread: Re: 'file changed'-event
- Next by thread: Re: 'file changed'-event
- Index(es):