In Perl, how can I watch a directory for changes?

后端 未结 2 741
清酒与你
清酒与你 2021-01-15 20:49
use Text::Diff;
for($count = 0; $count <= 1000; $count++){
   my $data_dir=\"archive/oswiostat/oracleapps.*dat\";
   my $data_file= `ls -t $data_dir | head -1`;
          


        
2条回答
  •  情歌与酒
    2021-01-15 21:43

    The real fix is File::ChangeNotify or File::Monitor or something similar (e.g., on Windows, Win32::ChangeNotify).

    use File::ChangeNotify;
    
    my $watcher = File::ChangeNotify->instantiate_watcher(
        directories => [ 'archive/oswiostat' ],
        filter => qr/\Aoracleapps[.].*dat\z/,
    );
    
    while (my @events = $watcher->wait_for_events) {
        # ...
    }
    

提交回复
热议问题