#!/usr/bin/perl use strict; use warnings; my @list = qw( one two three one one two_2 two_2 two two_2 two two_3 t +wo one ); @list = make_unique( @list ); print "@list\n"; sub make_unique { my (%seen, $try); map { my $n = $seen{$_}; $n++ while $seen{$try = $n ? $_ . "_$n" : $_}++; $try } @_; }
In reply to Re^2: Rename Duplicate List Elements in an Array
by Anonymous Monk
in thread Rename Duplicate List Elements in an Array
by awohld
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |