2013-03-18 21 views
-2
#!/usr/bin/perl 

use strict; 
use warnings; 

my $file; 
my @files; 
my $parse; 
my @files = <*>; 
foreach $file(@files) 
chomp ($file); 
{ 
$parse = system qq(paste <(cut -f1,2,13 $file) <(cut -f12 $file)); 
} 

"my" variable @files masks earlier declaration in same scope at Rast_seq.pl line 11. 
sh: 1: Syntax error: "(" unexpected 
sh: 1: Syntax error: "(" unexpected 
sh: 1: Syntax error: "(" unexpected 
sh: 1: Syntax error: "(" unexpected 
sh: 1: Syntax error: "(" unexpected 
sh: 1: Syntax error: "(" unexpected 

請幫我解決這個錯誤。在多個文本的Perl + Linux的重新排列列宿

+2

,如果你表現出樣品輸入/輸出這將是一件好事。爲此我使用shell命令是相當多餘的,我懷疑,但我不確定你想要做什麼。當字符串中出現括號而雙引號不用時,使用'qq()'是很愚蠢的。這是你的麻煩來源。 – TLP 2013-03-18 10:29:15

+0

你能解釋你想做什麼嗎?您正在使用Perl,然後調用系統命令。 '$ parse'是否包含一些有趣的東西?它唯一包含的是你的'system'命令的退出狀態。爲什麼不簡單地在Perl或shell中完成整個事情?如果我認爲我理解你在做什麼,那麼你可以完全在shell或Perl中完成,併爲自己節省很多麻煩。 – 2013-03-18 19:37:52

回答

1

移動開括號{chomp;
並刪除第一個my @files;
和改變qq

my $file; 
my $parse; 
my @files = <*>; 

foreach $file(@files) { 
    chomp ($file); 
    $parse = system qq#paste <(cut -f1,2,13 $file) <(cut -f12 $file)#; 
} 
+0

並將'qq()'更改爲'「」',因爲該字符串包含分隔符。 – TLP 2013-03-18 11:01:06

+0

@TLP:是的,當然:-) – Toto 2013-03-18 11:02:48

1

問題很少這裏的分隔符:

  • 您聲明數組@files兩次;
  • chomp ($file);for之外block;
  • chomp ($file);在這種情況下沒用:<*>返回文件名列表 - 你不讀行(我建議你使用glob '*';,因爲它更具可讀性);
  • system功能使用/bin/sh運行你的命令,它 - 因爲它似乎 - 不支持<(...)結構