wrkrbeee has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl -w use strict; use warnings; use File::stat; use lib "c:/strawberry/perl/site/lib"; #This program will extract Exhibit 21 info from 10-K filings; #Specify the directory containing the files that you want to read; my $files_dir = 'E:\research\audit fee models\filings\Test'; #Specify the directory containing the results/output; my $write_dir = 'E:\research\audit fee models\filings\filenames\filen +ames.txt'; #Open the directory containing the files you plan to read; opendir(my $dir_handle, $files_dir) or die "Can't open directory $!"; #Initialize file counter variable; my $file_count = 0; #Loop for reading each file in the input directory; while (my $filename = readdir($dir_handle)) { next unless -f $files_dir.'/'.$filename; print "Processing $filename\n"; #Initialize the variable names. my $line_count=0; my $access_num=""; my $cik=-99; my $name=""; my $stuff=""; my $line=""; #Open the input file; open my $FH_IN, '<',$files_dir.'/'.$filename or die "Can't open $filen +ame"; #Within the file loop, read each line of the current file; while (my $line = <$FH_IN>) { next unless -f $files_dir.'/'.$filename ; if ($line_count > 500000) { last;} ++$line_count; } #Open the ouput file; open my $FH_OUT, '>>',$write_dir or die "Can't open file $write_dir"; #Save the output to disk; print $FH_OUT "$line\n"; #close $FH_IN or die "unable to close $filename"; #Update file counter; ++$file_count; print "$line_count lines read from $filename\n"; #closedir($dir_handle); close($FH_OUT); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Read HTM, but no output
by Corion (Patriarch) on Apr 08, 2016 at 21:35 UTC | |
by wrkrbeee (Scribe) on Apr 08, 2016 at 21:38 UTC | |
|
Re: Read HTM, but no output
by 1nickt (Canon) on Apr 08, 2016 at 21:32 UTC | |
by wrkrbeee (Scribe) on Apr 08, 2016 at 21:34 UTC | |
by wrkrbeee (Scribe) on Apr 08, 2016 at 21:35 UTC |