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
說真的,吐了,這腳本寫得太爛了。