Ganesh Shankar wrote: > > Hello all, Hello,
> I'm starting to learn perl to convert files between different > bioinformatics programs. I'm aware of bioperl but want to learn some > basic perl before using those modules. > > 1) The script is in the same directory as the input folder, so open > should be able to find it. > > 2) The open input folder part works because I get a I get a list of the > files. > > 3) The whole program worked on a single file, but died when I tried to > convert it to handle a whole directory as input. > > 4) I'm developing on a Windows machine, so I think setting file > permissions are unnecessary, right? This problem is described is explained in the documentation for the readdir function. perldoc -f readdir [snip] If you're planning to filetest the return values out of a `readdir', you'd better prepend the directory in question. Otherwise, because we didn't `chdir' there, it would have been testing the wrong file. > Here's the code snippet: > > use warnings; > use strict; > > my @files = (); > my $folder = 'input'; > # Open the input folder > unless (opendir(FOLDER, $folder)) { > print "Cannot open folder $folder!\n\n"; > exit; > } > > #read the contents of the folder (files and subfolders) > @files = readdir(FOLDER); > > #Close the folder > print "\n\n Here are the files in the folder\n"; > #print out the filenames, one per line > print join( "\n", @files), "\n"; > closedir(FOLDER); > > foreach my $seqfilename (@files){ > [EMAIL PROTECTED] = @_; > $seqfilename = ''; > open (TXTFILE,"<$seqfilename") or die $!; open (TXTFILE,"<$folder/$seqfilename") or die $!; > close TXTFILE; > > my @seqelements = <TXTFILE>; > > ...........goes on from here > I know the conversion routine works, because it worked > when I specified a single file. John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]