#! /usr/local/bin/perl # use warnings; use Path::Class; use autodie; # die if problem reading or writing a file use Lingua::EN::Fathom; use Excel::Writer::XLSX; my $workbook = Excel::Writer::XLSX->new('output.xls'); my $worksheet = $workbook->add_worksheet(); my $file_handle = $worksheet->write(); my $text = new Lingua::EN::Fathom; opendir(DH, "./new_text"); my @files = readdir(DH); closedir(DH); foreach my $file (@files) { $text->analyse_file($file); $accumulate = 1; $text->analyse_block($text_string,$accumulate); $num_chars = $text->num_chars; $num_words = $text->num_words; $percent_complex_words = $text->percent_complex_words; $num_sentences = $text->num_sentences; $num_text_lines = $text->num_text_lines; $num_blank_lines = $text->num_blank_lines; $num_paragraphs = $text->num_paragraphs; $syllables_per_word = $text->syllables_per_word; $words_per_sentence = $text->words_per_sentence; %words = $text->unique_words; foreach $word ( sort keys %words ) { print("$words{$word} :$word\n"); } $fog = $text->fog; $flesch = $text->flesch; $kincaid = $text->kincaid; print($text->report); # Create a format for the book my $header = $workbook->add_format(); $header->set_bold(); my $percent_style = $workbook->add_format(); $percent_style->set_num_format('%'); # Add the line to the file foreach my $search ($text) { $worksheet->write(0, 0, "Filename",$header); $worksheet->write($count, 0, $file); $worksheet->write(0, 1, "Fog index",$header); $worksheet->write($count, 1, $fog); $worksheet->write(0, 2, "Flesch index",$header); $worksheet->write($count, 2, $flesch); $worksheet->write(0, 3, "Flesch-Kincaid index",$header); $worksheet->write($count, 3, $kincaid); $worksheet->write(0, 4, "Number of characters",$header); $worksheet->write($count, 4, $num_chars); $worksheet->write(0, 5, "Number of words",$header); $worksheet->write($count, 5, $num_words); $worksheet->write(0, 6, "Percent complex words",$header); $worksheet->write($count, 6, $percent_complex_words); $worksheet->write(0, 7, "Number of sentences",$header); $worksheet->write($count, 7, $num_sentences); $worksheet->write(0, 8, "Number of text lines",$header); $worksheet->write($count, 8, $num_text_lines); $worksheet->write(0, 9, "Number of blank lines",$header); $worksheet->write($count, 9, $num_blank_lines); $worksheet->write(0, 10, "Number of paragraphs",$header); $worksheet->write($count, 10, $num_paragraphs); $worksheet->write(0, 11, "Number of syllables per word",$header); $worksheet->write($count, 11, $syllables_per_word); $worksheet->write(0, 12, "Number of words per sentence",$header); $worksheet->write($count, 12, $words_per_sentence); $count++; } } $workbook->close();