Loading ...
Sorry, an error occurred while loading the content.
 

Counting the number of occurances of all paragraphs in a file

Expand Messages
  • Prateek Mathur
    Hi,       I want to count the number of times every paragraph appears in a text file. I want to print those paragraphs and the count of how many times
    Message 1 of 3 , Jul 20 12:51 AM
      Hi,

            I want to count the number of times every paragraph appears in a text file.
      I want to print those paragraphs and the count of how many times they appeared if the count is more than 1.

      e.g:
      file:

      p1

      p2

      p3

      p1

      p3

      p3

      It should print:
      p1
      Appeared 2 times

      p3
      Appeared 3 times.
       
      and so on for all the paragraphs that appear more than once.

      Let me know how can I do this Perl. I came across the split function but then that has to be used for every paragraphs and the text file can be very big as well to store in a single array.
      Also many paragraphs will appear only once which are not to be considered.

      Thanks in advance

      Prateek Mathur







      [Non-text portions of this message have been removed]
    • merlyn@stonehenge.com
      ... Prateek Let me know how can I do this Perl. I came across the split Prateek function but then that has to be used for every paragraphs and Prateek the
      Message 2 of 3 , Jul 20 7:32 AM
        >>>>> "Prateek" == Prateek Mathur <hiprateek007@...> writes:

        Prateek> Let me know how can I do this Perl. I came across the split
        Prateek> function but then that has to be used for every paragraphs and
        Prateek> the text file can be very big as well to store in a single
        Prateek> array. Also many paragraphs will appear only once which are
        Prateek> not to be considered.

        Set the value of $/ to "", then your filehandle reads will automatically
        be broken into paragraphs. Using the normal means of counting, you can
        then count each paragraph, and deliver a summary once the reading is
        complete.

        If this didn't smell like homework, I'd finish it for you.

        --
        Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
        <merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
        Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
        See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion
      • Prateek Mathur
        Hi,        What will be normal means of counting? Simplify my home work a bit more. :) Prateek Mathur ... From: merlyn@stonehenge.com
        Message 3 of 3 , Jul 23 4:13 AM
          Hi,
                 What will be normal means of counting? Simplify my home work a bit more. :)

          Prateek Mathur

          --- On Tue, 7/20/10, merlyn@... <merlyn@...> wrote:

          From: merlyn@... <merlyn@...>
          Subject: Re: [PBML] Counting the number of occurances of all paragraphs in a file
          To: "Prateek Mathur" <hiprateek007@...>
          Cc: perl-beginner@yahoogroups.com
          Date: Tuesday, July 20, 2010, 8:02 PM
















           









          >>>>> "Prateek" == Prateek Mathur <hiprateek007@...> writes:



          Prateek> Let me know how can I do this Perl. I came across the split

          Prateek> function but then that has to be used for every paragraphs and

          Prateek> the text file can be very big as well to store in a single

          Prateek> array. Also many paragraphs will appear only once which are

          Prateek> not to be considered.



          Set the value of $/ to "", then your filehandle reads will automatically

          be broken into paragraphs. Using the normal means of counting, you can

          then count each paragraph, and deliver a summary once the reading is

          complete.



          If this didn't smell like homework, I'd finish it for you.



          --

          Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095

          <merlyn@...> <URL:http://www.stonehenge.com/merlyn/>

          Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.

          See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion




























          [Non-text portions of this message have been removed]
        Your message has been successfully submitted and would be delivered to recipients shortly.