in reply to Re: Count occurrences and rename words in order
in thread Count occurrences and rename words in order

Thanks Monk
It works for the first line of the text file, but the events on the rest of the file continue the numeration from the first line, and the event from each line should be independent.
But I will it use to count the events in a whole document!!:)
  • Comment on Re: Re: Count occurrences and rename words in order

Replies are listed 'Best First'.
Re: Re: Re: Count occurrences and rename words in order
by davorg (Chancellor) on Sep 18, 2002 at 16:50 UTC

    You just need to reset %count to be empty before processing each line.

    while (<INPUT>) { my %counts; s|(/\w+)|$1 . ++$counts{$1}|ge; print OUTPUT; }
    --
    <http://www.dave.org.uk>

    "The first rule of Perl club is you do not talk about Perl club."
    -- Chip Salzenberg