Perl獲取匹配行之後的後幾行

2022-06-12 21:21:09 字數 377 閱讀 7663

#!/usr/bin/perl

open (f,"d:\\excel");

while ($lines=)

next if ($line_control==0);#next後面的不執行,直接跳到迴圈開始的地方,相當於python中contiue

print "$lines",if (grep $line_number..$line_number+10);#遍歷後面列表中的每個元素是不是和$.相等,就相當於檢查$.是不是在列表中

}$a=;

#關於grep可以詳細參看手冊

=pod

grep1..100

grep會先遍歷1..100中的每個元素,將其%2,如果結果結果為真就返回true

=cut

Perl的模式匹配

perl基本的模式匹配有兩種 m pattern 只匹配 s pattern replacement 匹配並替換其中分隔符反斜槓 可以用任意特殊字元替換 但在m pattern 簡寫為 pattern 時不能這樣做,換種說法,即若分隔符是反斜槓 則m pattern 可簡寫為 pattern 模式匹...

嚴格匹配 perl的文字匹配提取

perl的正規表示式極其強大,對於文字處理很有優勢。下面這個例子展示在ic驗證中怎麼利用perl的正規表示式做匹配提取。在ic驗證中會寫大量的task function,對很複雜的系統進行 的時候,會大量呼叫task function,如果能夠在進出task function的時候在log中列印出進...

Perl 輸出匹配到的某兩行之間的內容

usr bin perl open cdl,cdl or die open out,output.cdl or die while lines elsif lines ends and line control 1 if line control 1 close cdl close out usr ...