我試圖從文件中打印每一行,如果它們包含特定位置中的單個字符,則以'+'開始,但我將使用' - 」。該代碼運行,但沒有提供輸出,我相信這是一個非常簡單的錯誤,因爲我檢查了正則表達式,它的工作原理!匹配特定字符,如果找到則打印
FILE1數據:
3628 -a
9712 +T
11004 -a
11379 -a
12715 +T
14184 +T
輸出:
9712 +T
12715 +T
14184 +T
代碼:
#!/usr/bin/perl
use strict;
use warnings;
use autodie;
my $outputfile = "/Users/edwardtickle/Documents/indelfinal.txt";
open FILE1, "/Users/edwardtickle/Documents/indelcount.txt";
open (OUTPUTFILE, ">$outputfile");
while (<FILE1>) {
if (/^(\d+)\s+(\S)(\S)/) {
if ($2 =~ m/'+'/) {
print OUTPUTFILE "$1 $2$3\n";
}
}
}
close FILE1;
close OUTPUTFILE;
乾杯!
太棒了,感謝您的快速解決方案! – 2014-11-06 17:48:36