您好,恐怕我想问的不是文件的读写问题,而是对文本数据进行处理的问题。
在 2013年8月20日上午10:30,Hao Wu <echowu...@gmail.com>写道: > http://learn.perl.org/faq/perlfaq5.html > > A Perl program to do these tasks takes the basic form of opening a file, > printing its lines, then closing the file: > > open my $in, '<', $file or die "Can't read old file: $!"; > open my $out, '>', "$file.new" or die "Can't write new file: $!"; > > while( <$in> ) { > print $out $_; > } > > close $out; > > 参考learning perl input 与 output 章节。 > > > > 2013/8/19 李相辰 <lixiangche...@gmail.com> > >> 各位好,我有一个数据文件的文本,其中的数据格式如下: >> 1 69511 A G SNP rs75062661 OR4F5 ENST00000335137 >> 1 0.65 >> 1 69534 T C SNP rs190717287 OR4F5 ENST00000335137 >> 2 0.0005 >> 1 861275 C T SNP rs199884417 SAMD11 ENST00000598827 >> 0 0.0005 >> 1 861292 C G SNP rs191719684 SAMD11 ENST00000598827 >> 0 0.0014 >> 1 861315 G A SNP rs200140498 SAMD11 ENST00000598827 >> 0 0.0009 >> 1 863258 A G SNP rs185247114 SAMD11 ENST00000598827 >> 0 0.0005 >> 1 865544 C T SNP rs144245409 SAMD11 ENST00000342066 >> 1 0.0005 >> 1 865545 G A SNP rs201186828 SAMD11 ENST00000342066 >> 1 0.0018 >> 1 865584 G A SNP rs148711625 SAMD11 ENST00000598827 >> 1 0.01 >> ........... >> 我想对把 >> 1 69511 A G SNP rs75062661 OR4F5 ENST00000335137 >> 1 0.65 >> 转换成1 69511 A G SNP rs75062661 OR4F5 ENST00000335137 1 0.65 >> 也就是把没两行进行合并,然后添加一个制表符。 >> 本人新手,不太清楚perl是怎样实现~谢谢~ >> >> -- >> 您收到此邮件是因为您订阅了 Google 网上论坛的“PerlChina Mongers 讨论组”论坛。 >> 要退订此论坛并停止接收此论坛的电子邮件,请发送电子邮件到 perlchina+unsubscr...@googlegroups.com。 >> 要向此网上论坛发帖,请发送电子邮件至 perlchina@googlegroups.com。 >> 通过以下网址访问此论坛:http://groups.google.com/group/perlchina。 >> 要查看更多选项,请访问 https://groups.google.com/groups/opt_out。 >> > > -- > 您收到此邮件是因为您订阅了 Google 网上论坛的“PerlChina Mongers 讨论组”论坛。 > 要退订此论坛并停止接收此论坛的电子邮件,请发送电子邮件到 perlchina+unsubscr...@googlegroups.com。 > 要向此网上论坛发帖,请发送电子邮件至 perlchina@googlegroups.com。 > 通过以下网址访问此论坛:http://groups.google.com/group/perlchina。 > 要查看更多选项,请访问 https://groups.google.com/groups/opt_out。 > -- 您收到此邮件是因为您订阅了 Google 网上论坛的“PerlChina Mongers 讨论组”论坛。 要退订此论坛并停止接收此论坛的电子邮件,请发送电子邮件到 perlchina+unsubscr...@googlegroups.com。 要向此网上论坛发帖,请发送电子邮件至 perlchina@googlegroups.com。 通过以下网址访问此论坛:http://groups.google.com/group/perlchina。 要查看更多选项,请访问 https://groups.google.com/groups/opt_out。