Read to the next "\n>" and then fix up the line ends.
#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11113581 use warnings; my $filename = 'file.fasta'; open my $handle, '<', $filename or die "$! opening $filename"; my @array = map s/>\z//r =~ s/^(?!>)/>/r, do { local $/ ="\n>"; <$hand +le> }; use Data::Dumper; print Dumper \@array;
Or read the whole thing and split with a look-ahead for >
#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11113581 use warnings; my $filename = 'file.fasta'; open my $handle, '<', $filename or die "$! opening $filename"; my @array = split /(?=>)/, do { local $/; <$handle> }; use Data::Dumper; print Dumper \@array;
In reply to Re: Assigning multiple lines into first element of array
by tybalt89
in thread Assigning multiple lines into first element of array
by shabird
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |