#!/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\Exhibit21.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=""; my $htm =""; #Open the input file; open my $FH_IN, '<',$files_dir.'/'.$filename or die "Can't open $filename <:$!>"; use Cwd; print getcwd(), "\n"; #Within the file loop, read each line of the current file; $/=""; while (my $doc = <$FH_IN>) { #Begin new document section; if ($doc =~ m/^\s*(.*?)(ex21)/igm ) #if ($doc =~ m/^\s*(.*?)(ex21)(.*?)(.htm$)/igm || # $doc =~ m/^\s*(.*?)(EX-21)(.*?)(.htm$)/igm || # $doc =~ m/^\s*(.*?)(ex21)(.*?)(.htm$)/igm || # $doc =~ m/^\s*(.*?)(EX-21)(.*?)(.htm$)/igm) { $htm=join('',$1,$2); } print $htm; #close $FH_IN or die "Cannot close $filename: $!"; close $FH_IN; #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 "$htm\n"; #closedir($dir_handle); close($FH_OUT); } #end of document section; } #end of current file;