in reply to Assigning multiple lines into first element of array
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;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Assigning multiple lines into first element of array
by shabird (Sexton) on Mar 01, 2020 at 02:13 UTC | |
Re^2: Assigning multiple lines into first element of array
by shabird (Sexton) on Mar 01, 2020 at 03:09 UTC | |
by AnomalousMonk (Archbishop) on Mar 01, 2020 at 06:26 UTC | |
by tybalt89 (Monsignor) on Mar 01, 2020 at 08:08 UTC |
In Section
Seekers of Perl Wisdom