PERL 文件句柄||readline() on closed filehandle FILE ||Can't open file 解决方法
2020-02-29 19:05
31 查看
perl 文件句柄 *Perl readline() on closed filehandle FILE 或Can’t open file 问题解决方案 )
perl 读取一个文件,然后把读出来的数据写进另一个文件中去!
本人初学perl, 做基于人工智能的蛋白质结构预测课题,最近遇到一个问题,需要把200个单独的 标准fasta 文件(DSBs_10MHA.fasta) 整合到一个Total.fasta文件中,本以为很容易却一直报错,网上查找解决措施未果,自己最后用数组解决循环迭代。
详细过程如下
1. 输入及输出 ,
输入:DSBs_id_list.txt,200个DSBs_XXXXX.fasta,
输出:Total200.fasta.
2. 报错代码
#!/usr/bin/perl -w open TOTAL,">>total.fasta" or die " can't creat file"; open ID_LIST,"<DSBs_id_list.txt" or die " can't read file"; foreach my $id (<ID_LIST>) { open FASTA,"<seq_fasta/$id.fasta" or die " can't read file";; while (<FASTA>) { print TOTAL "$_\n"; } close FASTA; } close ID_LIST; close TOTAL;
报错
can’t read file at merge_fasta.pl line 7, <ID_LIST> line 754.
-
网络解决方案;
百度知道: https://zhidao.baidu.com/question/568388108.html
Stack Overflow: https://stackoverflow.com/questions/15014763/readline-on-closed-filehandle
~~然而这些解决方案本人亲试,并无卵用~ ~ -
最终我的解决方案;
用数组代替迭代循环
用数组代替迭代循环
用数组代替迭代循环
!/usr/bin/perl -w #################################### #**用数组代替迭代循环** #################################### open TOTAL,">>total.fasta" or die " can't creat file"; $ID_LIST = "<DSBs_id_list.txt"; open(IN, $ID_LIST); @ID_ARRAY = <IN>; close(IN); chomp(@ID_ARRAY); my $id=0 ; my $cnt = @ID_ARRAY; while ($id < $cnt) { my $complex_id = $ID_ARRAY[$id]; $id++; $fasta= "<seq_fasta/".$complex_id.".fasta"; open(IN, $fasta); @FASTA = <IN>; close(IN); chomp(@FASTA); print TOTAL "$FASTA[0]\n$FASTA[1]\n"; # FASTA 标准文件格式共两行 } close TOTAL;
结果正确输出无报错
之前也一直用CSDN的资源,第一次正式分享自己的一些学习经验,希望能帮到一些和我一样初学perl的小伙伴,如有错误请指正,skrskr
Skyline_sun_star
2018 .10 .27 夜 1:20
- 点赞
- 收藏
- 分享
- 文章举报
相关文章推荐
- 备份MySQL出现Can’t open file when using LOCK TABLES错误的解决方法
- Cant open file .../db/txn-current-lock: Permission denied的解决方法
- Cant open file /data/svn/dev/db/txn-current-lock: Permission denied的解决方法
- SVN报错:can't open file db/txn-current-lock:permission denied 解决方法
- 华硕笔记本激活WIN7时出现Can not open file C:/ Recovery.dat解决方法
- can't connect to MySQL server on 'localhost'的解决方法
- IllegalStateException: Can not perform this action after onSaveInstanceState的解决方法
- Vusial Studio提示“Cannot find or open the PDB file”解决方法
- Operation not permitted on IsolatedStorageFileStream解决方法(转)
- the file is already open in an editor 解决方法 .
- RAC srvctl 命令报 libpthread.so.0 cannot open shared object file No such file or directory 解决方法
- Android Studio出现Failed to open zip file问题的解决方法
- VC6.0启动File-open和Project-add file to project崩溃的解决方法
- evc4.0 MFC开发中,fatal error 1015 can't open file include aygshell.h 的解决办法
- Unable to open file dclusr60.lib解决方法
- error: #5: cannot open source input file "stm32f10x_conf.h": No such fi 解决方法
- Cannot open /var/log/sa/sa**: No such fileor directory解决方法
- navicat for mysql 远程连接数据库时出现2003-Can't connect to Mysql on '主机名'(10061)解决方法
- the file is already open in an editor 解决方法
- MySQL5.6 Using a password on the command line interface can be insecure解决方法;