perl File Tail模組的使用

2021-06-04 23:29:34 字數 572 閱讀 4281

最近在做乙個實時資料的工作,需要讀取不斷更新的檔案,類似shell中tail的功能,使用了perl的file::tail模組,簡要**如下

use file::tail;

my $file=file::tail->new(name=>&new_file($first_file_date),interval=>1,maxinterval=>10,tail=>-1,reset_tail=>-1,name_changes=>\&new_file,debug=>1);

while (defined(my $line=$file->read))

sub get_cur_date

if($mday<10)

$year.$mon.$mday;

}sub new_file;

引數說明:設定tail引數為正數,將從頭讀取檔案

設定name_change為乙個函式引用,即讀取當前檔案的下乙個檔案,本例中的檔案是以天記的

設定interval,即程式啟動後距離第一次讀取檔案的時間間隔

設定maxinterval,即當檔案沒有更新時,程式的sleep時間

參考:

模組的使用,模組的搜尋路徑

模組的使用 1 什麼是模組 模組是一系列功能的集合體 常見的模組形式 自定義模組 第三方模組 內建模組 1 乙個module.py檔案就是乙個模組,檔名是module.py,而模組名是module 2 乙個包含有 init py檔案的資料夾也是模組 3 已被編譯為共享庫或dll的c或c 擴充套件 4...

python模組 os模組的用法

1 os.getcwd 獲取當前工作的目錄,即當前python指令碼工作的目錄路徑 23 os.phdir dirname 改變當前指令碼的工作目錄 相當於shell下cd 45 os.curdir 返回當前目錄 67 os.pardir 獲取當前目錄字串名 89 os.makedirs dirna...

核心模組的makefile的製作(多模組)

hello.c include includemodule license gpl module author cfc module description hello linux module alias a module extern int add int a,int b extern int...