生物信息编程

十个非常有用的短perl程序

2019-08-09  本文已影响46人  周运来就是我

如果文本文件有许多重复的行,我们只想查看不重复的内容,就可使用下面的程序,把它们放到一个阵列中:

open(IN,"somefile.txt");
@Unique = ();
while (<IN>){unless($i{$_}++){push(@Unique,$_)}}

把多个连续的空白行压缩为一个空白行

open(IN,"somefile.txt");
$PrevBlank = 0;
while(<IN>)
if(/\S or ! $PrevBlank) {print $_}
$PrevBlank = /^\S*$/;
}
open(IN,"somefile.txt");
peint sort(<IN>);
sgowline 10 - 20 somefile.txt

open(IN, $ARGV[1]) or die "Could not read $ File. \n";
($Start, $Stop) = split(/-/,$ARGV[0]);
for($i = 1;$i<= $Stop; $i += 1)
    {$Line = <IN>;if($i>= $Start){print$ Line}}
foreach $ f ( < * > ){if(-f $f){print"$f\n"}}
foreach $f ( < * > ) {$i{ $f} =- $f};
foreach $k (sort { $i{ $b} < = >$i{$a}} keys %i)
    {printf"%8d%s\n", $i{$k},$k},
foreach $FullName( <* > ){
    ($Name, $Ext) = split(/\./,$FullName,2);
    push(@Temp,"$Ext\ t$FullName");
    }
    foreach $ Val(sort(@Temp)){
        ($Ext, $FullName) = split(/\ t/,$Val);
        print"$FullName\n";
        }
while( <STDIN> ) {
    $i = $_;chomp($i);unless($i) {last}
    $o = eval($i);print"Answer = $o \n";
}
my @TempList = ();
while (@MyList)
    {push(@TempList,splice(@Mylist,rand(@MyList),1))}
@MyList = @TempList;
print "Enter a seed number:";
$s = <STDIN>;
srand($s^time);
@c = split(/ */,"bcdfghjklmnprstv wxyz");
@v = split(/ */,"aeiou");
for($i = 1;$i<=4;$i+=1)
    {print $c[int(rand(20))],$v[int(rand(5))]}
上一篇 下一篇

猜你喜欢

热点阅读