Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re: Accessing File::Monitor attribute

by Crackers2 (Parson)
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.

Replies are listed 'Best First'.
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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://787768]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (2)
As of 2018-05-21 00:03 GMT
Find Nodes?
    Voting Booth?