user16709036
user16709036

Reputation:

How to rename duplicate value on Perl so they can have their own unique name ,So they are not duplicate anymore

So I encountered an issue with duplicate value.

$pdftitle = $2;
                $cleantitlepdf = substr($pdftitle , 0, 30 );
                $cleantitlepdf  =~ s/[^a-zA-Z0-9]//gmis;
                $uidname = $cleantitlepdf."UIDUL";

basically the $uidname has some duplicate value what I needed to do is not to remove the duplicate but to rename it so it will have its own unique name. so just for example.

$uidname = 04042020AmendmentUIDUL - There are 3 of this on the $uidname what I want is something like this.

04042020AmendmentUIDUL
04042020AmendmentUIDUL1
04042020AmendmentUIDUL2

Something like this? so they can have their own unique name. I'm not good with perl if anybody could help me on this I would greatly appreciate it.

Upvotes: 0

Views: 73

Answers (1)

ikegami
ikegami

Reputation: 385657

my %next_ids;

while (...) {
   ...

   my $uidname = $cleantitlepdf."UIDUL";
   $uidname .= $next_ids{ $uidname }++ // '';

   ...
}

Upvotes: 2

Related Questions