Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Polling a file for changes - Best Practices?

by choroba (Archbishop)
on Mar 04, 2020 at 22:31 UTC ( #11113788=note: print w/replies, xml ) Need Help??


in reply to Polling a file for changes - Best Practices?

I've used inotifywait for file polling several times. Usually without any module, just
open my $inotify, '-|', do { no warnings 'qw'; qw( inotifywait -m -r -e close_write -e moved_to --exclude /\ +.git/|~$|/#[^/]+# . ) } or die $!; while (<$inotify>) { my ($path, $event, $file) = split; $thread_queue->enqueue("$path$file") if $event =~ /$expected/; }

map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

Replies are listed 'Best First'.
Re^2: Polling a file for changes - Best Practices?
by Veltro (Hermit) on Mar 05, 2020 at 08:57 UTC

    Was there any reason why to depend on an external module/program? Did something like File::Tail not provide what you want?

      I don't think File::Tail can monitor a whole directory tree.
      map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
Re^2: Polling a file for changes - Best Practices?
by Tommy (Chaplain) on Mar 04, 2020 at 23:19 UTC

    What linux package provides `inotifywait`. Looks like inotify-tools from sourceforge, but I can't find it in any typical repo?? I'm looking at a github repo right now, but this doesn't feel mainstream...

    Tommy
    A mistake can be valuable or costly, depending on how faithfully you pursue correction
      Yes, it comes from sourceforge, but openSUSE provides it as a rpm package.

      map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

        Hmmm. Sadly not RHEL.

        Tommy
        A mistake can be valuable or costly, depending on how faithfully you pursue correction
      but this doesn't feel mainstream...

      There's a whole world of really good stuff which isn't "mainstream". Think for a moment how much of CPAN isn't in core. Does that stop you using those modules? Think how many Perl modules exist which are not provided as RedHat packages (that situation was really dire with RHEL5 and earlier and is only slightly better today). If you reach beyond the mainstream you will find a panoply of wondrous experiences.

      If you wanted something with a RedHat official seal of approval then this should have been stated up front in the OP. But there you already say you are using Mojolicious, websockets, etc. and your task doesn't sound particularly mainstream to me. Why the sudden aversion to downloading and installing inotifywait?

        "mainstream" was probably the wrong word to use. As I stated up front, I'm looking for best practices. It probably would have been more accurate for me to state at that it doesn't appear that there are very many best practices for this, which surprises me because it seemed to me like something common enough that it would have a recommended design pattern (at least in Perl)...

        To your point, I very well may have to go with something a little off the beaten path in order to achieve what's needed for this project. That's probably going to be just fine. I was somewhat hopeful that there were some more established guidelines and how to go about this, given that it felt like a kind of common need.

        Instead, I'm saying a lot of potentially great options, which isn't so bad! :-)

        Tommy
        A mistake can be valuable or costly, depending on how faithfully you pursue correction

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11113788]
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: (5)
As of 2020-06-04 18:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you really want to know if there is extraterrestrial life?



    Results (35 votes). Check out past polls.

    Notices?