[Pdx-pm] Accessing File::Monitor attribute

Daniel Herrington herda05 at gmail.com
Wed Aug 12 01:17:06 PDT 2009


Robert,

Thanks, that did it. Actually, I'm doing multiple files, so I had to 
make $monitor and array and the same with $filewatcher. What you 
provided got me over the hump though.

Dan H.

Robert Buels wrote:
> 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.
>
> Rob
>
>
>
> #!/usr/bin/perl
> 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--) {
>     $monitor->scan;
>     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
>
>

-- 
Daniel B. Herrington
Director of Field Services
Robert Mark Technologies
dherrington at robertmarktechnologies.com
o: 651-769-2574
m: 503-358-8575


More information about the Pdx-pm-list mailing list