pearlie has asked for the wisdom of the Perl Monks concerning the following question:
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: tie::file - file modification status
by Random_Walk (Prior) on Feb 09, 2005 at 16:42 UTC | |
OK, I think I got it working. forget Tie::Watch, I could not get that to work (though I am sure it can be made to) but I have created a little package called Sensitive_Array. this will set a global variable when the watched array is altered, dirty I know but that's the way the code grew. It also prints out the methods being called. I did not implement it all, but more than enough for this example. Make @watched_array the array your code is using, do not touch @array directly First the test code And here is the package, it is heavily borrowed from the example in the tie documentation Read more... (2 kB)
here is the output
Cheers,
Pereant, qui ante nos nostra dixerunt!
| [reply] [d/l] [select] |
|
Re: tie::file - file modification status
by Random_Walk (Prior) on Feb 09, 2005 at 13:19 UTC | |
I guess you can not do the obvious and patch in a flag to your code that is flipped by the same logic that decides whether to alter the tied array ?
Another other way would be to use Tie::Watch to notify you if changes are made to the file tied array. I am assuming you can chain these two together, will try some test code myself and report back later if I get time. you could also do an MD5 hash of your tied array when you first open it and compare this to one before you untie it. This is going to be a lot more costly than comparing the modification times. UpdateOK I have tried Tie::Watch and Tie::Array together and it looks like they do not chain. Whichever is done last is the only one in effect. My code is below in case a wiser monk than I can point out my error. It may still be possible to create a new array in place of the original, Tie::Watch it and have the methods in Tie::Watch call the appropriate update to the Tie::File array. Without further ado here is my test.
Cheers,
Pereant, qui ante nos nostra dixerunt!
| [reply] [d/l] [select] |