in reply to Re: How to do script to separate name and email domain ?
in thread How to do script to separate name and email domain ?

anakin30, I would have done something similar to Lady_Aleena's approach, but I would have just stored the count in the hash (see code below). Of course, my approach wouldn't have stored all the email addresses for later use like her code does.

use strict; my $file = "email_list.txt"; my %domains; open(DATA,"<",$file) || die "Unable to open file '$file': $!\n"; while (<DATA>) { my ($user,$domain) = split /\@/; $domain =~ s/^\s*//s; # Stripping out leading white spaces $domain =~ s/\s*$//s; # Stripping out trailing white spaces $domains{lc($domain)}++; } close(DATA); foreach my $domain (sort keys %domains) { print "$domains{$domain} $domain\n"; }

Just another example of TIMTOWTDI.

UPDATE - Made a minor spelling correction.