in reply to File not opening, but no error report
From a quick look, I don't see what is generating your output, but I do see a few things that will definitely slow you down.
1. You are reading filenames from the directory "/mnt/data/Programming", but opening those files in the current directory. If you are not in "/mnt/data/Programming", this should not open the files you intend.
2. You are modifying the directory you are reading by creating a file there. That is probably going to cause some confusion.
3. Since you are opening your output file with '>', you would overwrite it each time instead of accumulating output in that file. If you want to reopen each time, use '>>' instead.
4. You seem to be processing data one line at a time and also putting those lines in an array. I would probably only do one or the other.
I would probably get the list of files all at once and then process them from an array. For instance,
opendir ( my $dir, "/mnt/data/Programming") or die "Can't open directory: $!\n"; my @files = readdir( $dir ); closedir( $dir );
You can now process the files independently. The file open should really contain the path as well:
foreach my $file ( grep { -f "$path/$_" } @files ) { open( my $fh, '<', "$path/$file" ) or die "Unable to open '$file': $!\n"; while( <$fh> ) { # process each line here. } }
It's a good idea to check the names you get from readdir() to make sure they are files. You can't read directories as files (in general). Notice that I used lexical file and directory handles. Although not critical in this case, it will definitely save troubleshooting nasty problems in the future. Start on good habits early.
Update: Corrected file test to use path as shmem observed.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: File not opening, but no error report
by shmem (Chancellor) on Mar 25, 2009 at 21:20 UTC |