ckj has asked for the wisdom of the Perl Monks concerning the following question:
UPDATE: My program is in C:\Perl\bin and I'm entering the path to read & write files as C:\Perl where it gets failed but if I use C:\Perl\bin then it works fine. How to fix this issue?#!/usr/bin/perl use warnings; use strict; print "Enter the path where the log file is placed : "; my $dir =<>; chomp($dir); opendir DIR, $dir or die "cannot open dir $dir: $!"; my @files= readdir DIR; my $len=scalar(@files); print $len; print "Enter the path where to save the report"; my $dest_dir = <STDIN>; chomp($dest_dir); open(FH1,">$dest_dir./result.txt") if( $len > 0); foreach my $file (@files){ if($file=~/\.txt/){ print "$file\n"; open(FH,"$file") or die "Can't read the file \n"; while(my $line= <FH> ){ print FH1 $line; } close FH; } } close FH1; closedir DIR;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Unable to read a file
by tobyink (Canon) on Jun 13, 2012 at 06:59 UTC | |
|
Re: Unable to read a file
by rovf (Priest) on Jun 13, 2012 at 06:52 UTC | |
|
Re: Unable to read a file
by pvaldes (Chaplain) on Jun 13, 2012 at 08:44 UTC | |
|
Re: Unable to read a file
by ckj (Chaplain) on Jun 13, 2012 at 07:13 UTC | |
by Ken Slater (Initiate) on Jun 13, 2012 at 16:11 UTC | |
|
Re: Unable to read a file
by morgon (Priest) on Jun 13, 2012 at 16:57 UTC |