#! usr/bin/perl use File::Slurp; use warnings; use strict; # Output file: open(my $fh, ">", "output_new.csv") or die "cannot open > output_new.csv: $!"; # Specify the search strings here: my @txt = ( 'non-gaap( q\d)?(( (first|second|third|fourth)) quarter)? earnings(?! before)', 'non-gaap( q\d)?(( (first|second|third|fourth)) quarter)? net income', 'non-gaap( q\d)?(( (first|second|third|fourth)) quarter)? net loss', 'non-gaap( q\d)?(( (first|second|third|fourth)) quarter)? diluted', 'non-gaap( q\d)?(( (first|second|third|fourth)) quarter)? eps', 'non-gaap( q\d)?(( (first|second|third|fourth)) quarter)? per share', 'non-gaap( q\d)?(( (first|second|third|fourth)) quarter)? loss', 'adjusted( q\d)?(( (first|second|third|fourth)) quarter)? earnings per', 'adjusted( q\d)?(( (first|second|third|fourth)) quarter)? net income', 'adjusted( q\d)?(( (first|second|third|fourth)) quarter)? net loss', 'adjusted( q\d)?(( (first|second|third|fourth)) quarter)? eps', 'adjusted( q\d)?(( (first|second|third|fourth)) quarter)? per share', 'pro forma( q\d)?(( (first|second|third|fourth)) quarter)? earnings(?! before)', 'pro forma( q\d)?(( (first|second|third|fourth)) quarter)? net income', 'pro forma( q\d)?(( (first|second|third|fourth)) quarter)? net loss', 'pro forma( q\d)?(( (first|second|third|fourth)) quarter)? diluted', 'pro forma( q\d)?(( (first|second|third|fourth)) quarter)? eps', 'pro forma( q\d)?(( (first|second|third|fourth)) quarter)? per share', 'net income excluding', 'earnings excluding', 'per share excluding', 'per diluted share excluding', 'core( q\d)?(( (first|second|third|fourth)) quarter)? earnings per', 'core( q\d)?(( (first|second|third|fourth)) quarter)? net income', '\. excluding[^.]+?net income', '\. excluding[^.]+?net loss', '\. on a non-gaap basis[^.]+?(net income)', '\. on a non-gaap basis[^.]+?(net loss)', '\. on a non-gaap basis[^.]+?(per share)', '\. on a non-gaap basis[^.]+?(earnings(?! before))', 'non-gaap( q\d)?(( (first|second|third|fourth)) quarter)? net earnings', 'adjusted( q\d)?(( (first|second|third|fourth)) quarter)? net earnings', 'eps as adjusted', 'per share information excluding', 'effective tax rate non-gaap', 'tax (impact|effects?) of( non-gaap)? ((adjustments?)|(exclusions?))', 'before non-cash charges', 'non-gaap earnings before tax', 'net loss on a non-gaap basis', 'net income on a non-gaap basis', 'net earnings on a non-gaap basis', 'per share on a non-gaap basis', 'eps on a non-gaap basis', 'adjusted( net)? loss from continuing', '\. excluding[^.]+?earnings(?! before)', ); # Identify the number of search strings and store in $max: my $max=$#txt+1; # Create an array of length $max and print the header of the output file: my @word=(1..$max); $" = ',word'; print $fh "File_Number,word@word\n"; # Create an array based on the html files in the folder: my @files = glob '*.html'; # Slurp each file: foreach(@files){ # Store and print the file name, and ensure the file name is a number: my $current_file = ''; if(m/(^\d+)/){ $current_file = $1; } else{ next; } print "Processing $current_file \n"; # Store the file text in a scalar $text: my $text = read_file($_) ; ######################################################### # Clean the text: # ######################################################### # Drop HTML tags: # $text =~ s/<[^>]*?>/ /g; # # Fix dashes: # $text =~ s/&ndash;/-/gi; # $text =~ s/&mdash;/-/gi; # $text =~ s/–/-/g; # # Replace newlines and multiple spaces with one space: # $text =~ s/\s+/ /g; # # Remove parentheses and comma's # $text =~ s/\(//g; # $text =~ s/\)//g; # $text =~ s/,//g; # # Replace dots+numbers: # $text =~ s/\.\d//g; # ######################################################### # Match text by string and store matches in a dummy: my @indicator=(1..$max); my $index=0; foreach (@txt) { if(($text =~ m/$txt[$index]/i)){ $indicator[$index] = 1; } else{ $indicator[$index] = 0; } ++$index; } $" = ','; print $fh "$current_file,", "@indicator\n"; }