我試圖從文件底部的文件test.out中找到BLOB_SMUGHO的出現。如果找到,返回的數據塊,我很感興趣的字符串之間的「2014.10」查找多行塊
我得到初始化值$ CC的模式匹配(M //)使用在
這個腳本有什麼問題?
#!/usr/bin/perl
use strict;
use warnings;
use POSIX qw(strftime);
use File::ReadBackwards;
my $find = "BLOB_SMUGHO";
my $chnkdelim = "\n[" . strftime "%Y.%m", localtime;
my $fh = File::ReadBackwards->new('test.out', $chnkdelim, 0) or die "err-file: $!\n";
while (defined(my $line = $fh->readline)) {
if(my $cc =~ /$find/){
print $cc;
}
}
close($fh);
在情況下,如果這會有所幫助,這裏是test.out
2014.10.31 lots and
lots of
gibbrish
2014.10.31 which I'm not
interested
in. It
also
2014.10.31 spans
across thousands of
lines and somewhere in the middle there will be
2014.10.31
this precious word BLOB_SMUGHO and
2014.10.31 certain other
2014.10.31 words
2014.10.31
this precious word BLOB_SMUGHO and
2014.10.31
this precious word BLOB_SMUGHO and
which
I
will
be
interested
in.
樣本含量和我期待捕捉到的文本塊的所有多次出現從底部文件。
2014.10.31
this precious word BLOB_SMUGHO and
啊..我應該在我浪費我的時間這麼久之前發佈了這個問題。我很新,今天是我第一次用perl!非常感謝你。更多的問題,當我改變了上面的代碼一點,我能夠得到運算這樣 .10.31 這個珍貴的詞BLOB_SMUGHO和 .10.31 這個珍貴的詞BLOB_SMUGHO和任何想法我怎樣才能得到它像這樣: 2014年10月31日 這個珍貴的詞BLOB_SMUGHO和 2014年10月31日 這個珍貴的詞BLOB_SMUGHO和 我理解它得做ReadBackwards的工作方式,是有反正告訴ReadBackwards閱讀排除分界? – 2014-10-31 07:29:46
我正在接近答案,我的手機死了,我正試圖保存答案的最初部分,然後移動到PC(我現在在哪裏):( - 修改更多.... – codenheim 2014-10-31 07:36:32
tnq vm。the原因我沒有去sl is是因爲我正在處理一個大的文件(很容易超過幾千行)在CPU和內存敏感的機器上。 – 2014-10-31 07:40:16