in reply to Re: How to find the repeated text in hash
in thread How to find the repeated text in hash
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.
|
|---|
| 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 |