I am opening a directory that has files that look like the following. Here is one file:
>UVWXY
ABCDEFGHIJKLMNOPQRSTUVWXYZ
>STUVW
ABCDEFGHIJKLMNOPQRSTUVWXYZ
>QRSTU
ABCDEFGHIJKLMNOPQRSTUVWXYZ
Here is a second file:
>EFGHI
ABCDEFGHIJKLMNOPQRSTUVWXYZ
Here is my code:
#!/usr/bin/perl
use warnings;
use strict;
my ($directory) = @ARGV;
my $dir = "$directory";
my @ArrayofFiles = glob "$dir/*";
open(OUT, ">", "/path/to/output.txt") or die $!;
foreach my $file(@ArrayofFiles){
open(my $fastas, $file) or die $!;
my $numberoffastas = grep{/>/}<$fastas>;
#print $numberoffastas, "\n";
while (my $line = <$fastas>){
print $line, "\n";
}
}
Nothing is printed out for $line, but this code correctly counts the number of ">"s that appear in the file when it is opened, evidenced by printing $numberoffastas.
How can I fix this code so that $line = something like:
>EFGHI
or
ABCDEFGHIJKLMNOPQRSTUVWXYZ
Thanks