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 4597202
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T23:13:25+00:00 2026-05-21T23:13:25+00:00

I have been struggling with this for a couple days now and cannot seem

  • 0

I have been struggling with this for a couple days now and cannot seem to figure it out.

I have an array of email addresses that were created via push(@emails,$email) in a while loop.

I am attempting to create a list of unique domains with occurrence count of each in the array.

Ordered by number of occurrences.

So, if the array @emails has:

john@yadoo.com ringo@geemail.net george@zoohoo.org paul@yadoo.com

I can print:

yadoo.com 2
geemail.net 1
zoohoo.org 1

I found this example based on emails in a file but, WAY over my head. Can someone help me in a more verbose code example that can be used with an array of email addresses?

perl -e 'while(<>){chomp;/^[^@]+@([^@]+)$/;$h{$1}++;}
foreach $k (sort { $h{$b} <=> $h{$a} } keys %h)  {print $h{$k}." ".$k."\n";} infile

I also tried: (more to my level of lack of understanding)

foreach my $domain (sort keys %$domains) {
  print "$domain"."=";
  print $domains->{$domain}."\n";
};

AND

my %countdoms;
$countdoms{$_}++ for @domains;
print "$_ $countdoms{$_}\n" for keys %countdoms;

The best result I got of many different attempts was a total count (which was 1812 (accurate count) with a number 2 next to it. I am close, possibly?

  • 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-21T23:13:26+00:00Added an answer on May 21, 2026 at 11:13 pm

    If you have your email address populated in an array this’ll get you a count for each domain. I’m sure someone can produce something prettier!

    my @emails = ('john@yadoo.com','ringo@geemail.net','george@zoohoo.org','paul@yadoo.com');
    
    my %domainCount;
    
    foreach(@emails){
        if ($_ =~ /@(\w+.*)/){
            $domainCount{$1}++;
        }
    }
    
    for my $domain (sort { $domainCount{$b} <=> $domainCount{$a}} keys %domainCount ){
        print "$domain - $domainCount{$domain}\n";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been struggling with this for several days now and I ran out
I have been struggling with this one for days and can't seem to figure
I have been struggling with this problem for a few days now and I
I have been struggling with a problem for a couple of days now with
I've been struggling with this issue for a couple of days now. I need
I've been struggling for a couple of days now with this problem on QTcpSockets
I've been struggling with this for a couple days now. I'm trying to make
Been struggling with this for a couple days now. Here's the set up -
I have been struggling with this for three days now and this is what
So I've been struggling with this for the last couple days.. I have music

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.