Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Please, format you codes properly.
If I understand your questions, you want to

  • Store up each file read in an array, for later use
  • Count the difference between the total number of letters between two sentences

One way of doing the first step is shown below, however, the second step you will figure it out! I know you can!:)
I commented out all the second part. Since, the first part gives you all your array elements, then you can find the difference between the total number of letters.
#!/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 = <STDIN> ); LOOP: while ( $input !~ m{^\bquit\b}i ) { # Input a sentence print "\n\n Please type the filename(.txt): "; chomp( my $filename = <STDIN> ); next LOOP if $filename eq ""; # go back to LOOP if filename is em +pty # 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 comp +arisons push @all_sentences, $sentence; print "\n Type \"quit\" to quit or press ENTER to continue: "; chomp( $input = <STDIN> ); } 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 e +tc. # 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=$di +ff_letters\n"; #print $fh "\n Difference of letters between sentence2 & sentence3=$di +ff_letters\n"; #print $fh "\n Difference of letters between sentence1 & sentence3=$di +ff_letters\n\n"; #close $output; # Line 47 # exit the program #exit;
I can only hope this helps.

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others contemplating the Monastery: (8)
    As of 2017-09-19 13:47 GMT
    Find Nodes?
      Voting Booth?
      During the recent solar eclipse, I:

      Results (221 votes). Check out past polls.