gpt4 book ai didi

perl - 如何在 Windows 上使用 File::ChangeNotify?

转载 作者:行者123 更新时间:2023-12-04 19:07:23 26 4
gpt4 key购买 nike

我安装了 File::ChangeNotify在 Windows 系统上并尝试运行以下代码:

my $watcher =
File::ChangeNotify->instantiate_watcher
( directories => [ 'C:\files' ],
filter => qr/\.txt$/
);


# # blocking
while ( my @events = $watcher->wait_for_events() ) { print "new event"}

当我运行脚本并尝试创建一个新的 .txt 时文件或修改 .txt文件下 c:\files该脚本没有打印任何内容。

最佳答案

如果我添加这一行,它对我有用(在 linux 上):

$| = 1;

然后我看到 new event .

引用 perldoc perlvar : $|$OUTPUT_AUTOFLUSH
这是完整的代码:
use warnings;
use strict;
use File::ChangeNotify;

$| = 1;

my $watcher =
File::ChangeNotify->instantiate_watcher
( directories => [ 'C:\files' ],
filter => qr/\.txt$/
);


# # blocking
while ( my @events = $watcher->wait_for_events() ) { print "new event"}

更新:正如 cjm 敏锐地指出的那样,添加换行符可以替代 $| :
 while ( my @events = $watcher->wait_for_events() ) { print "new event\n"}

关于perl - 如何在 Windows 上使用 File::ChangeNotify?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21146445/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com