在perl中,如何讀取兩個標記之間的內容。像這樣的源數據perl腳本讀取標記之間的內容
START_HEAD
ddd
END_HEAD
START_DATA
eee|234|ebf
qqq| |ff
END_DATA
--Generate at 2011:23:34
那麼我只想在「START_DATA」和「END_DATA」之間獲取數據。這個怎麼做 ?
sub readFile(){
open(FILE, "<datasource.txt") or die "file is not found";
while(<FILE>){
if(/START_DATA/){
record(\*FILE);#start record;
}
}
}
sub record($){
my $fileHandle = $_[0];
while(<fileHandle>){
print $_."\n";
if(/END_DATA/) return ;
}
}
我寫這段代碼,它不起作用。你知道爲什麼嗎 ?
感謝
感謝
爲了將來的參考,「不起作用」是不是很豐富。您應該包含錯誤消息或其他有關不工作的信息。 – TLP
'while while {print if/START_DATA/../ END_DATA /}' –