On Jan 24, 2008 3:34 PM, <[EMAIL PROTECTED]> wrote: > What I really want to do is monitor a directory recursively but here > just trying to use it any basic way to start to `get' how to use it. >
For starter, you haven't turned on the recurse flag. Take another look at the arguments to File::Monitor->watch(), particularly "Recurse" and "Files." > Taking one of the examples offered at: > http://search.cpan.org/~andya/File-Monitor-0.10/lib/File/Monitor/Object.pm > This is probably your first mistake. File::Monitor uses File::Monitor::Object internally. You shouldn't be mucking with F::M::O directly unless you have a really good reason (i.e. F::M doesn't provide functionality you need). Instead of playing with the F::M::O example, take a look at the F::M example. Since this is what we have to work with at the moment, though... > With a few minor (but probably wrong) changes I get nothing printed > when the file is altered during the sleep. The program just runs 10 > seconds and closes. > > The example seems to be saying in the comments to just run > $monitor->scan; `later' and changes will be available. > > #!/usr/bin/perl > > use strict; > use warnings; > > use File::Monitor; > use File::Monitor::Object; > > my $monitor = File::Monitor->new(); > > my @files = ( "./oldwork/test"); > for my $file ( @files ) { > $monitor->watch( $file ); > } > Without the recurse option, this just watches the directory, not the files in it. So unless you're adding or deleting files... > # First scan just finds out about the monitored files. No changes > # will be reported. > $monitor->scan; > sleep 10; > > # Later perform a scan and gather any changes > for my $change ( $monitor->scan ) { > # $change is a File::Monitor::Delta > > ## Also tried `print "$File::Monitor::Delta\n" -hp; > > print "change<$_>\n"; > } $File::Monitor::Delta is an object. Even if it exists, attempting to print it won't produce anything useful. Maybe something like: print "change:\t" , $change->name, "\n"; Finally, Tom's points are important. How do you *know* that the files (in this case a single directory) changed *during the sleep*? Do you know that the output wasn't buffered? That the system didn't delay the writes for some reason? That you were even watching the files you thought you were? Your best bet to make sure the module is working would, instead of sleeping between scans and trying to modify the watched files from an external process during a narrow window, would probably be to perform your initial scan; open one of the watched files for writing; write to it; flush the buffer; close it; and then rescan. HTH, --jay -------------------------------------------------- This email and attachment(s): [ ] blogable; [ x ] ask first; [ ] private and confidential daggerquill [at] gmail [dot] com http://www.tuaw.com http://www.downloadsquad.com http://www.engatiki.org values of β will give rise to dom!