in reply to Re: How to find the repeated text in hash
in thread How to find the repeated text in hash

My guess is that the OP wants to edit the values of an existing hash. Each value that is not unique should be made so by appending an integer.
use strict; use warnings; use Data::Dumper; my %example = ( a => 'red', b => 'blue', c => 'red', d => 'green', e => 'red', ); my %desired = ( a => 'red', b => 'blue', c => 'red1', d => 'green', e => 'red2', ); my %seen; while (my ($letter, $color) = each %example) { if ($seen{$color}++) { $example{$letter} = $color . $seen{$color}; next; } $example{$letter} = $color } print Dumper( \%desired, \%example );

UPDATE: Added example.

Bill

Replies are listed 'Best First'.
Re^3: How to find the repeated text in hash
by QM (Parson) on Feb 10, 2015 at 14:59 UTC
    This is a minimalist answer, and is easily ambiguous:
    Each value that is not unique should be made so by appending an integer.

    Perhaps you mean something like:

    Before inserting a hash key, if it already exists, string increment the key and try again.

    -QM
    --
    Quantum Mechanics: The dreams stuff is made of