我有一個叫list.txt
文件,它看起來像這樣:(它有500行)的Perl:如何指定開始行「/」
/apps/gtool/0.7.5/gtool -M --g gen1.txt etc
/apps/gtool/0.7.5/gtool -M --g gen2.txt etc
/apps/gtool/0.7.5/gtool -M --g gen3.txt etc
我要讓.SH腳本的每一行LIST.TXT。我能做到這一點在Perl,但我有一個問題,因爲我不知道怎麼行至候開始/
我的腳本如下:
use strict;
use warnings;
open (IN, "<list_for_merging_chunks.sh");
while (<IN>)
{
if ($_=~ m/^/apps.*\n/)
{
my $file = $_;
$file =~ s/.*\> //;
$file =~ s/\.txt/.sh/;
$file =~ s/\n//;
open (OUT, ">$file");
print OUT "\#!/bin/bash\n\#BSUB -J \"$file\"\n\#BSUB -o
/scratch/home/\n\#BSUB -e /scratch/home/$file\.out\n#BSUB -n 1\n\#BSUB -q
normal\n\#BSUB -P DBCDOBZAK\n\#BSUB -W 168:00\n";
print OUT $_;
close OUT;
}
}
exit;
我得到一個錯誤:
Bareword found where operator expected at merging_chunks.pl line 7, near "*\n"
(Missing operator before n?)
"my" variable $file masks earlier declaration in same statement at
merging_chunks.pl line 10.
"my" variable $file masks earlier declaration in same scope at
merging_chunks.pl line 11.
"my" variable $file masks earlier declaration in same scope at
merging_chunks.pl line 12.
"my" variable $file masks earlier declaration in same scope at
merging_chunks.pl line 14.
"my" variable $file masks earlier declaration in same scope at
merging_chunks.pl line 15.
"my" variable $file masks earlier declaration in same statement at
merging_chunks.pl line 15.
"my" variable $file masks earlier declaration in same statement at
merging_chunks.pl line 15.
"my" variable $_ masks earlier declaration in same scope at merging_chunks.pl
line 16.
syntax error at merging_chunks.pl line 7, near "*\n"
syntax error at merging_chunks.pl line 20, near "}"
Execution of merging_chunks.pl aborted due to compilation errors.
我認爲這是與該文件做:if ($_=~ m/^/apps.*\n/)
它似乎不喜歡它用/
開始的事實。無論如何,我可以解決這個問題嗎?我假設有一個特殊字符可以用來以某種方式告訴Perl?非常感謝。