On Jun 21, 8:15 am, [EMAIL PROTECTED] (Luba Pardo) wrote: > I want to parse through some files of a list of directories. Every directory > have the same files, which means that I can make a loop and repeat the > process for each directory. I managed to write the code to process the files > of a single directory but I do not exaclty how to read a list of directories > and open one by one. I can only print the directories that are in the > parental directory , but I can't make the script to open the directory and > read the list of files. I do not what is the function to use to either open > everydir or read the 'subdirectories'.
I can't parse this sentence. If you meant "I do not know what is the function", then you want the File::Find module. See `perldoc File::Find`. If you meant "I do not want to read the subdirectories", then use the filetest operators (`perldoc -f -X`) to determine whether each entry is a file or a directory, and skip over the directories. > I hope someone can help > The beginning of the script looks like: > > #! /usr/bin/perl > use strict; > use warnings; > > my $pwd=$ENV{'PWD'}; > my @filedir =<*ctt>; > foreach my $filedir (@filedir) { > opendir ($filedir) || die "can't \n"; > my @f = <mlc*>; This does not do what you think it does. opendir() only opens a directory for reading via readdir(). It does not change the current working directory of your script. You have two options: 1) Change working directory, and then ask the shell for all files in the current working directory 2) Open a directory, and read the files in that directory. You, however, are opening a directory, and then asking the shell for all the files in the current working directory. Change these two lines to either: opendir my $dh, $filedir or die $! my @f = grep /^mlc/, readdir($dh); or chdir $filedir or die $! my @f = <mlc*>; (You were also calling opendir() without a directory handle argument - I'm suprised that didn't give you a syntax error). See also: perldoc -f opendir perldoc -f chdir perldoc -f readdir perldoc -f glob Hope that helps, Paul Lalli -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/