I'm currently working with dozens of FASTA files, and I'm tired of having to manually change the filename in my Perl script.
I'm trying to write a simple Perl script that'll create a 2-dimensional array containing the name of the folders and its contents.
For example, I would like the output to look something like this:
Folder A iam.fna a.fna new.fna
Folder B to.fna perl.fna
Folder C filehandling.fna
Folder D please.fna help.fna me.fna
I would like to access these folders recursively, but I am new to perl filehandling, and I'm completely clueless where to begin. Any help will be appreciated! Thank you in advance.
That'll be my entire directory. I only have fasta files in the various folders. I would like to list out the names of folders with its contents because the names of the folders are quite similar, and I'd like to list them all out.
In perl there are lot of module to handle the files.like File::stat.also there is a simple way to read a directory.We can use the option like -d,-f,-l.Using this we can check whether the given thing is a file or directory or link file.
For example I am reading my current directory which having some number of directories .Here is the simple way,
#!/usr/bin/perl
use strict;
use warnings;
my $dir = ".";
opendir(DIR, $dir) or die $!;
while(defined (my $file = readdir(DIR)))
{
if(-d "$file")
{
opendir(newDIR, $file) or die $!;
print "Folder " . $file . ":\n" ;
while(defined ($file = readdir(newDIR)))
{
print "$file,"; # Here you can do some specific operation on the file
}
print "\n\n";
closedir(newDIR);
}
}
closedir(DIR);
To read the get the files in current directory we can use the glob function.
my @arr=glob ".* *";
foreach(@arr)
{
print "$_ \n";
}