Check for double!


How to check and delete double entries?

$test = "test|234|wert|234|test"

after the check the result has to be:

$test = "test|234|wert"
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

$test = "test|234|wert|234|test";
foreach $Item (split(/\|/, $test)) {
  $Items{$Item} = 0;
$test = join('|', keys(%Items));
$test = "test|234|wert|234|test";
for (@fields = split '|', $test) {
@fields = grep {exists $hash{$_} ? do {delete $hash{$_}; 1;} : undef;} @fields;
$test = join '|', @fields;
olthoff's answer is fine if you don't need to preserve the order of the fields in the line.
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

`perldoc -q "How can I extract just the unique elements of an array"`
$test = "test|234|wert|234|test";
$test = join '|',grep{!$hash{$_}++} split/\|/,$test;
mmcwAuthor Commented:
Question to ozo:

Is it possible to make it so that lowwercae or uppercase doesn't matter and that test and Test is the same!

$test = test|Test|wat


$test = test|wat
$test = join '|',grep{!$hash{lc $_}++} split/\|/,$test;
#or, if you don't need to preserve the order or case with olthoff's answer
@Items{split/\|/,lc $test} = ();
$test = join('|', keys(%Items));

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.