Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Accessing File::Monitor attribute

by Crackers2 (Vicar)
on Aug 11, 2009 at 20:56 UTC ( #787768=note: print w/ replies, xml ) Need Help??


in reply to Accessing File::Monitor attribute

I think you need something more like the below:

use File::Monitor; use File::Monitor::Object; my $wFileMonitor = File::Monitor->new(); $wFileMonitor->watch($wFile); #-- First scan does nothing $wFileMonitor->scan; #-- Let's sleep so changes can happen sleep 10 #-- Subsequent calls will report changes my @changes = $wFileMonitor->scan; foreach my $object (@changes) { my $modified = $object->mtime; }

Since you're only monitoring one file I guess you'll get either 0 or 1 objects back from scan depending on whether the file changed or not.

Objects are of class File::Monitor::Delta as shown in the docs.


Comment on Re: Accessing File::Monitor attribute
Select or Download Code
Re^2: Accessing File::Monitor attribute
by herda05 (Acolyte) on Aug 11, 2009 at 21:13 UTC
    Thanks, I was thinking along those lines and wrote some code to try and do that. However, Deltas only get populated when changes occur. So in the end, it appears the file actually has to change for me to get mtime? That doesn't seem to make sense.

    This line from the doc is what throws me:

    "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."

    Am I nuts or does that seem to indicate you can simply call on the methods after the initial scan is run?

    The trouble is I want to determine if I should exit after the first scan based on an mtime passed on the command line. If the file's mtime and the mtime passed in are true in some relative way (lt,gt,ne,eq) then there's no need to go further and do deltas.

      I can't seem to find the line you quote in the docs. If I'd had to guess I'd say they're probably referring to the old_* fields in the delta object, which let you compare the values before and after the change.

      Why don't you just query the files directly and only add them to the monitor if the mtime is fine? You have the filename, so you can just do a stat on it directly, can't you?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://787768]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (8)
As of 2014-09-02 07:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (20 votes), past polls