A. 如何用perl获取某一文件所在路径
用perl获取某一文件所在路径,参考代码如下:x0dx0ax0dx0ause Cwd 'abs_path'x0dx0aprint abs_path($0)."\n";x0dx0aman Cwdx0dx0aNAMEx0dx0aCwd - get pathname of current working Cwd;x0dx0amy $dir = getcwd;x0dx0ause Cwd 'abs_path'x0dx0amy $abs_path = abs_path($file);
B. 用perl处理代码
#!/usr/bin/perl -w
use strict;
open FD,">>", "D:/I100A-Z.txt"|| die "can't open file $!";
open FS,">>", "D:/I1000-9.txt"|| die "can't open file $!";
open FH,">>", "D:/E00A-Z.txt"|| die "can't open file $!";
open FM,">>", "D:/E000-9.txt"|| die "can't open file $!";
while(<DATA>){
if(/I00.([A-Z].*)/){
print FD "$1\n";
}
elsif(/I00[0-9]\s\d{3,5}\s([A-Z]*)/){
print FS "$1\n";
}
elsif(/E\d\d\d\s\d{1,3}\s([A-Z]*)/){
print FM "$1\n";
}
elsif(/E\d\d\d([A-Z]*)/){
print FH "$1\n";
}
}
__DATA__
1_NC_003279
I001 109 TTTAATAGCTTTTATGATTCAAAAAG 134 249
E012 1 TTCATCATCTTCTAGAATTCACAATG 26 146
26 49
I002 986 GGGTATCAAAAGTATTAGAAAGC 1008 3400
E023 142 GGGTATCGGACGTGTTACAAAGC 164 200
23 70
2_NC_003279
I001 3235 CTCCTATTTTTTGTTGTG 3252 3262
E012 16 CTGCTATCTTTTGTTGCG 33 149
18 63
C. 请问这段perl代码是什么意思,请详细点,谢谢!
#!usr/bin/perl-w
usestrict;
use5.014;
openIN,"<",$ARGV[0]ordie"readfileerror ";#以只读方式打开文件,文件句柄为IN,文件名为命令行里的第一个参数
openOUT,">",$ARGV[1]ordie"outerror ";#新建文件,文件句柄为OUT,文件名为命令行里第二个参数
while(<IN>){#逐行读入文件,以下为按行操作
chomp;
if(/Molecule:ZINC/){
s/Molecule://;#行替换,替换掉"Molecule:",即将"Molecule:ZINCfoo"这样的行替换为"ZINCfoo"
s/s//g;#继续替换上一行,替换掉剩余的所有空格(包括空格,横竖制表符,换行符,换页符),即将"ZINCfoo"替换为"ZINCfoo"
printOUT;#将替换完的行写入文件(命令行里第二个参数)
}elsif(/AmberScore:/){
s/AmberScore://;#和上面一样,替换掉“AmberScore:”以及所有空格,并写入刚才打开的那个文件,写入时每行的格式为:“制表符”“被替换以后的行内容”“换行符”
s/s//g;
printOUT" $_ ";
}
}
总结一下, 就是读入这样的文本:
Mole:fuck1
AmberScore:998
Mole:fuck2
AmberScore:101
Mole:fuck3
AmberScore:250
然后输出这样的文件:
fuck1998
fuck2101
fuck3250
说真的,吐了,这脚本写得太烂了。