#!/usr/bin/perl use strict; use warnings; my @all_sentences; ## initialized an array my $sentence = ""; print "\n Type \"quit\" to quit or press ENTER to continue: "; chomp( my $input = ); LOOP: while ( $input !~ m{^\bquit\b}i ) { # Input a sentence print "\n\n Please type the filename(.txt): "; chomp( my $filename = ); next LOOP if $filename eq ""; # go back to LOOP if filename is empty # open the file or exit open my $fh, '<', $filename or die "Cannot open file $filename: $!"; my $sentence = do { local $/; <$fh> }; ## slurp a file close $fh or die "can't close file: $!"; # To remove white space & fullstop $sentence =~ s/\s|\.//g; print "\n Sentence: $sentence\n"; # To count number of total letters my $total_letters = 0; $total_letters = length($sentence); print "\n Total letters in the sentence= $total_letters\n"; # To store all sentences as elements in the array for further comparisons push @all_sentences, $sentence; print "\n Type \"quit\" to quit or press ENTER to continue: "; chomp( $input = ); } print join "\n", @all_sentences; ## a test to show you got all the file content # To find the difference of letters between pairs of sentences i.e. # sentence1 & sentence2, sentence2 & sentence3,sentence1 & sentence3 etc. # Find the difference of letters between any two sentences # Line 37 #my $diff_letters = # code #? ?? # ? ?; # Line 38 #print"\n Difference of letters between sentence1 & sentence2=my $diff_letters\n #Difference of letters between sentence2 & sentence3=my $diff_letters\n #Difference of letters between sentence1 & sentence3=my $diff_letters\n\n\n"; # Print to a text file: #my $output="Result .txt"; # Line 42 #open (my $fh,">",$output) or die"Can't open file '$output'.\n";# Line 43 #print $fh "\n Difference of letters between sentence1 & sentence2=$diff_letters\n"; #print $fh "\n Difference of letters between sentence2 & sentence3=$diff_letters\n"; #print $fh "\n Difference of letters between sentence1 & sentence3=$diff_letters\n\n"; #close $output; # Line 47 # exit the program #exit;