leon951 has asked for the wisdom of the Perl Monks concerning the following question:

Dear PerlMonks, I am new to perl and have a project to do. I need to know how to create a file handler on a unix directory. I want to dump records into a directory and need a perl script to do some processing as soon as the data dump occur without user intervention. Is this possible and how?

Replies are listed 'Best First'.
Re: Event handler
by Your Mother (Archbishop) on May 30, 2011 at 19:50 UTC

    I have used Linux::Inotify2 and been happy. You will need to be running something that has inotify, of course. OS X does not qualify for example; there you could try IO::KQueue.

    File::ChangeNotify seems to be more agnostic and I’ve used tools that rely on it but never coded up anything with it directly myself.

    Update 31.05.2011: I just discovered File::Monitor as well which seems nice and makes recursive monitoring easier than the inotify stuff.

      Thanks for the input. File::Monitor was the answer to my problem. Once again, thank you
Re: Event handler
by rgcosma (Beadle) on May 30, 2011 at 19:49 UTC
    Your problem is more complicated than might seem: various Unixes signal filesystem events in completely different ways, which of them are you running? Even if you just say "Linux", is it FAM or inotify? A few hints on the flavour and version of running system will help a lot in getting a plausible answer, and also a sample workflow.
Re: Event handler
by anonymized user 468275 (Curate) on May 31, 2011 at 08:48 UTC
    You first need to choose a scheduler. cron is the most usual, being a standard feature of the O/S, although autosys provides more advanced functionality. There are plenty of others too, like Tivoli Workload Scheduler.

    Suppose it's cron, then you would do something like

    0,15,30,45 * * * * /home/projectX/fred.pl >fred.out 2>&1
    and put something like this in fred.pl
    my @found = glob '/data/projectX/ftpin/*' or exit;

    One world, one people