rahulruns has asked for the wisdom of the Perl Monks concerning the following question:
I need to read all the files in a directory line by line with one file handle. But I am getting error when it reads the first file
opendir(my $dh, "/tmp/files"); my @files=readdir($dh); closedir $dh; my $index = 0; $index++ until $files[$index] eq "."; splice(@files, $index, 1); $index++ until $files[$index] eq '..'; splice(@files, $index, 1); foreach my $file ( @files ) { print "\n\nThe File is $file\n\n"; open (MYFILE, "<$file") or die $! ; while (<MYFILE>) { chomp; if ( $_ =~ m/map/i ) { print "$_ in $file\n"; } } close (MYFILE); } Error [root@r01mgt functionaltest]# perl checkfunctional.pl The File is mrbench_result No such file or directory at checkfunctional.pl line 22.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Reading all files in a directory with one filehandle
by tinita (Parson) on Apr 03, 2013 at 09:40 UTC | |
by rahulruns (Scribe) on Apr 03, 2013 at 09:43 UTC | |
by marto (Cardinal) on Apr 03, 2013 at 09:45 UTC | |
Re: Reading all files in a directory with one filehandle
by Loops (Curate) on Apr 03, 2013 at 09:37 UTC | |
Re: Reading all files in a directory with one filehandle
by blue_cowdawg (Monsignor) on Apr 03, 2013 at 18:54 UTC | |
Re: Reading all files in a directory with one filehandle
by hdb (Monsignor) on Apr 03, 2013 at 09:41 UTC | |
Re: Reading all files in a directory with one filehandle
by kejohm (Hermit) on Apr 03, 2013 at 22:32 UTC |
Back to
Seekers of Perl Wisdom