On Nov 7, 2010, at 11:15 PM, shawn wilson wrote: > Ooh, I didn't know about inotify.
Yeah, this is much more appealing. Looks like Linux::Inotify2 is better-supported than Linux::Inotify. > It would seem that you can either use it > within perl (just keep the script running like a service) or from a command > line. I think it really comes down to how often you're expecting new files. > And I don't know how the perl module works - its possible you might have to > spawn a fork in case another file comes in while you are working. It looks like the Inotify2 "streaming interface" allows you to block until "read" notification(s) come in (my @events = $inotify->read). I haven't absorbed the details yet, but it sounds like I can read a notification, handle it, and then loop back and read others that may have occurred in the meantime -- in a strictly serialized fashion, without any worries. Pretty neat. Cheers and thanks! Chap > On Nov 8, 2010 12:04 AM, "Ishwor Gurung" <ishwor.gur...@gmail.com> wrote: >> Hi. >> >> On 8 November 2010 15:46, Chap Harrison <c...@pobox.com> wrote: >>> >>> On Nov 7, 2010, at 6:47 PM, shawn wilson wrote: >>> >>>> its Unix, I'd use cron as its probably already running. And do something >>>> like: script.pl $(find <path> -type f -print0) Every few seconds. >>> >>> That looks plenty straightforward enough, except how does one prevent a > race condition wherein cron launches another instance of script.pl before > the first instance has exclusively grabbed responsibility for loading the > newly-arrived files? >> >> Using a temporary file might be one approach. i.e., in your code, you >> write one when processing, exit if it exists in other subsequent code. >> This way no code can gobble up each other's resources even though >> polling isn't the coolest thing on earth - it does the job. >> >> If you want to tackle it another way, check out dnotify/inotify syscalls. >> >> HTH. >> >> [...] >> -- >> >> Regards >> Ishwor Gurung >> Key id:0xa98db35e >> Key fingerprint:FBEF 0D69 6DE1 C72B A5A8 35FE 5A9B F3BB 4E5E 17B5 >> >> -- >> To unsubscribe, e-mail: beginners-unsubscr...@perl.org >> For additional commands, e-mail: beginners-h...@perl.org >> http://learn.perl.org/ >> >> -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/