我尝试将数据与换行符和其他一些数据进行匹配但不起作用。 我的perl代码
open(data,"filename");
@file = <data>;
@get = grep{m/^\>.*\n.*/} @file;
print "$get[1]";
我的文件就像这样
>1AA7
LSLLSEVESFVLSVVPSGPLKAEVAQKLEEVFAGKQSELEVLLEFLKSKPVLSPLSKGVLGFVFSLSVPSEKGLQKKKFVQQALQGQGEPQQLEKAVKLFK
>1ABV
SEFVSVAKPFAKAAFEFAVEKQSVEKFQELLAFAAEVSKQEQLAELLSGALAPESLAESFVAVCGEQLEEQGQQLVKVLAEQGKLQALPEVLEQFVKLKAVSEASAEVEVVSAAALSEQQLAKVSAALEKKLSK
>1AEP
AAGKVQVAEAVQQLQKSVVQAAKELKESLGLPSPEEALQLLSEQAQAFKSKVAEVSSSLKQEAEKKQGSVAEQLQAFAKQLQQSVKEAASSLQLQEQLQSLQSALSQVGKQFQEVASKSQASAQEAFAPVQSALQEAAEKSKEAAAQLQQSVQSAVQKPAQ
在此程序中,仅输出>1ABV
不能使用\n
和我的代码中的另一个字符。但我希望这段代码的输出
>1ABV
SEFVSVAKPFAKAAFEFAVEKQSVEKFQELLAFAAEVSKQEQLAELLSGALAPESLAESFVAVCGEQLEEQGQQLVKVLAEQGKLQALPEVLEQFVKLKAVSEASAEVEVVSAAALSEQQLAKVSAALEKKLSK
答案 0 :(得分:1)
看起来你想要段落模式进行阅读。
您可以通过修改$INPUT_RECORD_SEPARATOR
:
use strict;
use warnings;
local $/ = ''; # Paragraph mode
my @data = <DATA>;
print $data[0];
__DATA__
>1AA7
LSLLSEVESFVLSVVPSGPLKAEVAQKLEEVFAGKQSELEVLLEFLKSKPVLSPLSKGVLGFVFSLSVPSEKGLQKKKFVQQALQGQGEPQQLEKAVKLFK
>1ABV
SEFVSVAKPFAKAAFEFAVEKQSVEKFQELLAFAAEVSKQEQLAELLSGALAPESLAESFVAVCGEQLEEQGQQLVKVLAEQGKLQALPEVLEQFVKLKAVSEASAEVEVVSAAALSEQQLAKVSAALEKKLSK
>1AEP
AAGKVQVAEAVQQLQKSVVQAAKELKESLGLPSPEEALQLLSEQAQAFKSKVAEVSSSLKQEAEKKQGSVAEQLQAFAKQLQQSVKEAASSLQLQEQLQSLQSALSQVGKQFQEVASKSQASAQEAFAPVQSALQEAAEKSKEAAAQLQQSVQSAVQKPA
输出:
>1AA7
LSLLSEVESFVLSVVPSGPLKAEVAQKLEEVFAGKQSELEVLLEFLKSKPVLSPLSKGVLGFVFSLSVPSEKGLQKKKFVQQALQGQGEPQQLEKAVKLFK
注意:数组索引从Perl中的0开始。
答案 1 :(得分:1)
如果要将多个换行符分隔的内容读入数组,
use strict;
use warnings;
use autodie;
my @get = do {
open(my $data, "<", "filename");
local $/ = "";
<$data>;
};
$ /
[...]设置为&#34;&#34;将两个或多个连续的空行视为一个空行。