Hi,
I have a text file where some words/events occur more than once in the same line. I have to number them in the order of appeareance. I was checking previous user's question about counting occurrences but at the end what it generates is a total of occurrences for each word, and what I need is, having this line:

doc123/print doc456/read doc789/print doc145/print doc123/read

The output will be:
doc123/print1 doc456/read1 doc789/print2 doc145/print3 doc123/read2

So I need the counting, and the renaming of each event(same word) adding a number in the order that event occurs.
I created a hash table where the key is the event and the "count" is the value, but before update the count I concatenated the value to the event in a another variable, and join each result, for each line the count start in zero (0). But it doesn't work!!! >:(

it is ok that I used hash tables or is there another way, maybe with just regular expressions?

Thanks!!

In reply to Count occurrences and rename words in order by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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, details, 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, summary, 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.