wrkrbeee has asked for the wisdom of the Perl Monks concerning the following question:
#! /usr/bin/perl -w use strict; use warnings; use lib "c:/strawberry/perl/site/lib"; use open ':std', ':encoding(UTF-8)'; #Specify location of input files; my $files_dir = 'D:\research\audit fee models\filings\test'; #Specify location of output results; my $write_dir = 'D:\research\audit fee models\filings\filenames\filena +mes.txt'; #Open the directory containing the input files you will loop through; opendir (my $dir_handle, $files_dir); #Set up a loop for the sequentially reading the input files; while (my $filename = readdir($dir_handle)) { next unless -f $files_dir.'/'.$filename; print "Procesing $filename\n"; #Open the next file in the directory; open my $fh_in, '<', $files_dir.'/'.$filename or die "failed to open '$filename' for read"; #Open the output file for saving the results; open my $fh_out, '>', $write_dir.'/'.$filename or die "failed to open '$filename' for write"; #Initialize file counter; my $count=0; #Establish a loop to read the open file line by line; while (my $line = <$fh_in>) { #begin WHILE loop; print $line; print $fh_out "$line\n"; #write results to file; ++$count; #update line counter; } #end of while loop for current line; print "$count lines read from $filename\n;" } #end of current file loop;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Failed to open file for write
by Laurent_R (Canon) on Apr 13, 2016 at 06:25 UTC | |
|
Re: Failed to open file for write
by BrowserUk (Patriarch) on Apr 12, 2016 at 23:16 UTC | |
by SimonPratt (Friar) on Apr 13, 2016 at 12:10 UTC | |
by wrkrbeee (Scribe) on Apr 12, 2016 at 23:26 UTC | |
by BrowserUk (Patriarch) on Apr 12, 2016 at 23:32 UTC | |
by wrkrbeee (Scribe) on Apr 12, 2016 at 23:35 UTC | |
by Marshall (Canon) on Apr 12, 2016 at 23:58 UTC | |
| |
by BrowserUk (Patriarch) on Apr 12, 2016 at 23:59 UTC | |
| |
|
Re: Failed to open file for write
by jellisii2 (Hermit) on Apr 13, 2016 at 16:58 UTC |