Using IO::Event to detect new files in a directory
perl
Solution
I recommend you to use File::ChangeNotify and File::ChangeNotify::Watcher for that.
use File::ChangeNotify;
my $watcher =
File::ChangeNotify->instantiate_watcher
( directories => [ '/my/path', '/my/other' ],
regex => qr/\.(?:pm|conf|yml)$/,
);
if ( my @events = $watcher->new_events() ) { ... }
$watcher->watch($handler);
Problem
I am trying to use IO::Event to detect when a new file is added to a directory. I am new to the IO::Event library, and would like to know if it can be easily implemented. I tried the code below to see if I can get it to do something with no luck. It crashed when I tried to use `opendir` instead of `open`. I am just looking to see if this library can provide me with what I am looking for. I don't need a solution in plain Perl as I can code it myself. the only reason I am looking at this is because I want to use Proc::JobQueue::EventQueue. I can code the solution just using Proc::JobQueue, but thought that this might be cleaner. ``` #!perl use warnings; use strict; use IO::Event; open my $dirhandle,'/some/path/here/'; my $event = IO::Event->new($dirhandle); Event::loop(); close $dirhandle; sub ie_input{ print "ie_input called\n"; } sub ie_read_ready{ print "ie_read_ready called\n"; } sub ie_werror{ print "ie_werrory called\n"; } sub ie_output{ print "ie_output called\n"; } ```