I tried using the sample provided by lostjimmy but I don't totally understand what its doing now.. all it does is give me some file names and the following output here is the code now.. and my output is below it. I would like for it to go through all directories and open all the files testing each and reporting if one does not contain the proper number of fields.<code> opendir(DIR, "c:\\mlx\\") || die "can't opendir: $!"; my @list = grep { $_ ne '.' && $_ ne '..'&& $_ ne 'copy.pl' } @list=readdir(DIR); foreach my $name (@list) { $path="c:\\mlx\\$_"; shift @list; print $name, "\n"; opendir(DIR, "$path\\$name"); my @files=grep {$_ ne '.' && $_ ne '..'} @files=readdir(DIR); foreach $file(@files){ print "filename is ", $file, " \n"; print "and I am in directory ", $name, " \n"; } } example of echoing contents of file.. open (FILE, '04-22-2009.txt'); while (<FILE>) { chomp; ($timeoftest, $login, $searchload, $searchresults, $searchdetails,$add +listing,$editlisting,$logout,$sitecode) = split(","); print "time of test: $timeoftest\n"; print "login: $login\n"; print "searchload: $searchload\n"; print "searchresults: $searchresults\n"; print "searchdetails: $searchdetails\n"; print "addlisting: $addlisting\n"; print "editlisting: $editlisting\n"; print "logout: $logout\n"; print "sitecode: $sitecode\n"; print "---------\n"; } close (FILE); exit;
output..#use strict; #use warnings; opendir(DIR, "c:\\mlx\\") || die "can't opendir: $!"; my @list = grep { $_ ne '.' && $_ ne '..'&& $_ ne 'copy.pl' } readdir( +DIR); foreach my $name (@list) { $path="c:\\mlx\\$_"; shift @list; print $name, "\n"; opendir(DIR, "$path\\$name"); my @files=grep {$_ ne '.' && $_ ne '..'}readdir(DIR); foreach $file(@files){ print "filename is ", $file, " \n"; print "and I am in directory ", $name, " \n"; chdir $name; print "I am in directory $name"; open (FILE, '$file')|| die "Cannot open file $file"; while (<FILE>) { chomp; ($timeoftest, $login, $searchload, $searchresults, $searchdetails,$add +listing,$editlisting,$logout,$sitecode) = split(","); print "time of test: $timeoftest\n"; print "login: $login\n"; print "searchload: $searchload\n"; print "searchresults: $searchresults\n"; print "searchdetails: $searchdetails\n"; print "addlisting: $addlisting\n"; print "editlisting: $editlisting\n"; print "logout: $logout\n"; print "sitecode: $sitecode\n"; print "---------\n"; } close (FILE); exit; } }
C:\>perl 2.pl 03-27-2009.txt 04-02-2009.txt 04-07-2009.txt 04-09-2009.txt 04-13-2009.txt 04-15-2009.txt 04-17-2009.txt 04-21-2009.txt 04-23-2009.txt AAR filename is 04-16-2009.txt and I am in directory AAR Cannot open file 04-16-2009.txt at 2.pl line 22. I am in directory AAR
In reply to testing files for valid content by grashoper
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |