[Pdx-pm] Accessing File::Monitor attribute

Robert Buels rmb32 at cornell.edu
Tue Aug 11 15:31:04 PDT 2009

Not such great documentation.  From what I can tell, watch() returns a 
monitoring object, and you call mtime on that.

Here's a demo.  run it like demo.pl filename to watch a file for 
modifications for 10 seconds.


use strict;

use File::Monitor;
use File::Monitor::Object;
my $monitor = File::Monitor->new();
my $filewatcher = $monitor->watch($ARGV[0]);
print $filewatcher->mtime, "\n";
my $n = 10;
while($n--) {
     sleep 1;
     print $filewatcher->mtime, "\n";

Daniel Herrington wrote:
> All,
> I'm new to classes in perl and I've hit a roadblock using the 
> File::Monitor class. From the doc for  File::Monitor 
> http://search.cpan.org/~andya/File-Monitor-0.10/lib/File/Monitor/Object.pm 
> <http://search.cpan.org/search?mode=module&query=File%3A%3AMonitor>:
> The state of the monitored file or directory at the time of the last 
> scan can be queried. Before scan is called these methods will all return 
> undef. The following methods return the value of the corresponding field 
> from "stat" in perlfunc.
> For example:
> my $modified = $object->mtime;
> Now I've instantiated my object as per the instructions:
> use File::Monitor; use File::Monitor::Object; my $wFileMonitor = 
> File::Monitor->new(); $wFileMonitor->watch($wFile); $wFileMonitor->scan; 
> my $modified = $wFileMonitor->mtime
> But I get the following error:
> Can't locate object method "mtime" via package "File::Monitor" at 
> /home/workspace/watchFile.pl line 65.
> I know it's getting lost in the reference to mtime, but I'm at a loss on 
> how to access it. The doc simply refers to $object->mtime and my read of 
> it says that $wFileMonitor should be $object.
> thanks,
> -- 
> Daniel B. Herrington
> Director of Field Services
> Robert Mark Technologies
> dherrington at robertmarktechnologies.com
> o: 651-769-2574
> m: 503-358-8575
> ------------------------------------------------------------------------
> _______________________________________________
> Pdx-pm-list mailing list
> Pdx-pm-list at pm.org
> http://mail.pm.org/mailman/listinfo/pdx-pm-list

Robert Buels
Bioinformatics Analyst, Sol Genomics Network
Boyce Thompson Institute for Plant Research
Tower Rd
Ithaca, NY  14853
Tel: 503-889-8539
rmb32 at cornell.edu

More information about the Pdx-pm-list mailing list