JabberJay58 has asked for the wisdom of the Perl Monks concerning the following question:

Hello !

I'm new here and I need a little help.. First I'm sorry for my bad english, I hope you can understand me. I'm making a perl program, and I have to count the words in a .txt

The thing is, I added the "meter" (not sure if this is the right noun) and I need to show all the words and then the meter but only once. But my program prints the meter after every word and I don't know how to do.

I can write down my program but it is in french..

I really hope you can help me..

Replies are listed 'Best First'.
Re: Insert a meter only once
by SuicideJunkie (Vicar) on Nov 20, 2015 at 17:27 UTC

    Your program will be mostly in perl rather than french, so it should be ok ;)

    This is just guessing; perhaps you mean 'tallies' or 'statistics' or 'summary'.

    I imagine you have a loop to iterate over the words and print them. It sounds like you have the print statement for the "meter" inside the loop, so it prints each time. Simply moving it outside the loop will make it only run once.

Re: Insert a meter only once
by toolic (Bishop) on Nov 20, 2015 at 16:58 UTC
    The best way for us to help is if you post the smallest code example that we can run and which also demonstrates the problem you have. Make sure to also post the output you get and the output you expect. Use "code" tags: read Writeup Formatting Tips. See also http://sscce.org

      Further to toolic's post: I have no idea what the word meter means in the context of the OP. The only application to written text I can think of has to do with poetry (see the linked word definitions). Is "meter" in your context something like a "metric", a "measure", perhaps a "total count"? A short, executable example might clarify this.

      Update: Oops... Meant to reply to JabberJay58 in the main thread, not to toolic. Oh, well...


      Give a man a fish:  <%-{-{-{-<

        Well 'compteur' in French means 'counter' (as in 'compteur de mots' = 'word counter').

        But 'compteur' also means 'meter', as in electricity/gas meter, or the meter in a taxi.

        So I guess the OP is really looking to count distinct words in a text.

Re: Insert a meter only once
by Lennotoecom (Pilgrim) on Nov 21, 2015 at 20:34 UTC
    $s += (s/\w+//g) while <DATA>; print "amount: $s\n"; __DATA__ Your excuses, Sir, are actually somewhat funny. But in reality you should apply a bit of yourself, or eventually you may get nothing.