Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6006267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:30:52+00:00 2026-05-23T01:30:52+00:00

I need to find the duplicate values in a perl hash and then output

  • 0

I need to find the duplicate values in a perl hash and then output the key/value pair and associated dup count when that count is > 1.

(I could leave a code sample of what I’ve attempted but that would just result in mass confusion and possibly uncontrolled laughter, and I’m really hoping to make it through life with some semblance of self esteem.)

Hash key/value would look like the following:

%hash = qw('FHDJ-124H' => 'hostname1', 'HJDHUR-87878' => 'hostname2', 'HGHDJH-874673' => 'hostname1');

My desired output would be:

2 duplicates found for hostname1
    FHDJ-124H
    HGHDJH-874673

Using perl 5.6 on Solaris 10. Tightly controlled production environment where upgrading or loading perl mods is not allowed. (A change request for moving to 5.8 is about 6 months out).

Many thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T01:30:53+00:00Added an answer on May 23, 2026 at 1:30 am

    You need to iterate through the hash keys in your first hash (key/value) and accumulate the count of each item you find in another hash (value/count).

    If you want to display the keys together with duplicated values, your second hash cannot be as simple as that, since for each duplicated value you will have a collection of keys (all of them having the same value). In this case, simply accumulate the key in an array, then count its elements. I.e., your second hash would be something like (value/[key1,key2,key3…])

    my %hash = ( key1 => "one", key2 => "two", key3 => "one", key4 => "two", key5 => "one" );
    my %counts = ();
    foreach my $key (sort keys %hash) {
        my $value = $hash{$key}; 
        if (not exists $counts{$value}) {
            $counts{$value} = [];
        }
        push $counts{$value}, $key;
    };
    

    Then iterate over $counts to output what you need when the count of elements in $counts{$value} > 1

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am trying to create sql procedure or function that need to find duplicate
I need to write a query that will go through a table, find duplicate
I need to find/create an application that will create employee web usage reports from
Writing a simple program that will find exact duplicate files on my computer, but
Here's a quick question I need to duplicate values in a sprintf function sprintf(%s
Possible Duplicate: Compute Median of Values Stored In Vector - C++? I need to
I need to find duplicate entries in my db table. There has to be
Possible Duplicate: How to retrieve the values for the particular key from CFMutableDictionary In
I have a List of integer's with duplicate values in it. What I need
I'm trying to find duplicate customers in a table that looks like this: customer_id

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.