Check for file and process it, existence of file launch script - perl -
how can write perl program wait input file created , process contents of file? ideally should cross-platform solution rather relying on features of given operating system.
note file might exist script started, or might created @ later date. once input file has been processed perl program can exit.
[note substantially edited version of original question. original poster should feel free make additional edits if didn't understand question.]
take @ file::monitor. inform of sorts of file system events. program shows how monitor file creation in specific directory , process new xml files.
use strict; use warnings; use 5.010; use file::monitor; $monitor = file::monitor->new; $monitor->watch( { name => 'e:\perl\source', files => 1, callback => { files_created => \&files_created } } ); while () { @new = $monitor->scan; sleep 1; } sub files_created { ($name, $event, $change) = @_; $file ( $change->files_created ) { process_xml($file) if $file =~ /\.xml$/i; } } sub process_xml { ($file) = @_; $file; }
Comments
Post a Comment