in reply to Count occurrences and rename words in order

Not quite sure what this is needed for, but the following seems to meet your requirements well enough.

#!/usr/bin/perl use warnings; use strict; my $test = 'doc123/print doc456/read doc789/print doc145/print doc123/ +read'; my %count; print join '/', grep {s/^([a-z]+)\s/"$1".(++$count{$1}).' '/ie || $_} split '/', $test;

Replies are listed 'Best First'.
Re: Re: Count occurrences and rename words in order
by Anonymous Monk on Sep 18, 2002 at 16:41 UTC
    Thanks for your help, It works!! Just one question why do you need to check the beginning of the string?
    I need this for reschedule the events according with document (DOC) parameters.

      After the split on '/' each part is tested individually, since it looks like the command bit has to start at the beginning of the segment- and because I like to make my regexps as specific and safe as possible- I added the ^ anchor there.