求一个perl的脚本

2025-03-12 15:01:11
推荐回答(2个)
回答1:

#!/usr/bin/perl -w
use strict;
die "perl $0 \n" unless(@ARGV == 2);
open IN,$ARGV[0] || die "打开输入文件失败\n";
open OUT,">$ARGV[1]" || die "打开输出文件失败\n";
while(){
if($_=~/^>/){
print $_;
print OUT $_;
}
if($_=~/^Type/){
print $_;
print OUT $_;
}
if($_=~/^Retained introns/){
print $_;
print OUT $_;
}
}
close IN;
close OUT;

运行的时候,假设你保存为脚本RunPick.pl
输入文件名为 input.txt 输出文件名为output.txt
那么运行时直接:perl RunPick.pl input.txt output.txt
运行结束之后,屏幕会回显你要的那几行信息以及将你要的信息保存到output.txt里面。如果还有其他疑问,请补充提问

回答2:

你的程序没有问题的啊,要是替换多个短语加个for就好了
$| = 1;
chomp(my $keyword = <>);
while(){
s/$keyword//g;
print $_;
}
__DATA__
123 123 456
789 123
456 123 33

while (<>)
{
chomp;
last if (! length );
push @words, $_;
}
while(){
for $keyword(@words){
s/$keyword//g;
}
print $_;
}