in reply to Perl script for concatenating multiple files in aspecific order listed in a txt file
Hello Anonymous Monk,
I see already the fellow Monks have provided you with plenty of options. I just would like to provide two more possible solutions.
But I still lost, what is the a specific order of the files in your file? Is it in numerical order?
Since you did not provide us with an example of your file and expected output I will just assume, and propose something. Why not extract all FASTA files from the file in an array and simply concatenate them with the join?
Just a suggestion if I have understand correctly.
Provide us more information so we can help you.
Solution one using File::Slurp/read_dir:
#! /usr/bin/perl use strict; use warnings; use File::Slurp; use Data::Dumper; my $dir = '.'; my @files = read_dir($dir); @files = sort @files; @files = grep {$_ ne '.' && $_ ne '..'} @files; print Dumper \@files; __END__ $ perl test.pl $VAR1 = [ 'test.pl', 'test.pl~', 'test_1.txt', 'test_2.txt', 'test_2a.txt', 'test_2b.txt', 'test_2c.txt', 'test_3.txt' ];
Solution two using readdir:
#! /usr/bin/perl use strict; use warnings; use Data::Dumper; my $dir = '.'; opendir( my $dh, $dir) or die "Cannot open ".$dir." - $!"; my @files = sort readdir($dh); @files = grep {$_ ne '.' && $_ ne '..'} @files; closedir $dh or warn "Cannot close ".$dir." - $!"; print Dumper \@files; __END__ $ perl test.pl $VAR1 = [ 'test.pl', 'test.pl~', 'test_1.txt', 'test_2.txt', 'test_2a.txt', 'test_2b.txt', 'test_2c.txt', 'test_3.txt' ];
Sorry I miss understood the question.
Looking forward to your update, BR.
|
|---|