Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I'm trying trying to process all .dat files in a nested directory tree. I've used the File::Find module but it's not working how I expected it to work. I can't even concatenate the directory and the filename to open the files. I always get the error message "readline() on closed filehandle"
Any help would be deeply appreciated!
Here is the code:
use strict; use warnings; use Cwd; my $startdirectory = cwd; print "Starting directory: $startdirectory\n"; use File::Find; find ( \&inFiles, ('.') ); exit; sub inFiles { chomp; my $name = $_; my $directory = cwd; if( $name =~ /.dat/) { print "dir = $directory\tname = $name\n"; open INFILE,'<$name' || warn ("Cannot open input file $name\n"); my @infilecontent = <INFILE>; print @infilecontent; my $localfile = "$directory\$name"; #win32 open INFILE2,'<$localfile' || warn ("Cannot open input file $localf +ile\n"); @infilecontent = <INFILE2>; print @infilecontent; } } #inFiles
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to open files found via File::Find
by ikegami (Patriarch) on Jan 08, 2010 at 00:30 UTC | |
by jwkrahn (Abbot) on Jan 08, 2010 at 07:28 UTC | |
|
Re: How to open files found via File::Find
by gam3 (Curate) on Jan 08, 2010 at 00:33 UTC | |
by roboticus (Chancellor) on Jan 08, 2010 at 14:07 UTC | |
by gam3 (Curate) on Jan 08, 2010 at 19:15 UTC |