473,385 Members | 1,764 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Need help with getting unique values in a file.


Sorry for asking, but I give up on this situation. I am a total n00b at
Perl and have only used it for about 1 week now. I would really
appreciate somebody's help here because I am really feeling stuck.

I have a list of 1000's of email addresses in a file ( This is not a
spam list first and foremost ). I need to read that file in and create
unique lists sorting by domain. A particular domain must be listed once
per list. To make this a bit more clear....

If my addresses in the source file are as follows:

bill at one.com
jane at one.com
frank at two.com
ted at one.com
jess at three.com

My first run should return:
--------------------
bill at one.com
frank at two.com
jess at three.com

2nd run:
------
jane at one.com

3rd run:
------
ted at one.com

I came up with this to grep unique domains once, but the problem is
that the script only runs once.

#!/usr/bin/perl -w

sub div() { "+","-" x 50, "+\n"; }

die "Usage: $0 emailList" if (@ARGV!=1);

open( EML, $ARGV[0] ) || die "Can't open file : $!\n";

while(<EML>){
*chomp;
*push(@addys, $_) if $_ =~
/^[a-zA-Z0-9_\.\-]+\@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$/;
}

close( EML );

foreach $email( @addys ) {
*@parts = split( "@", $email );
*$domain = $parts[1];
*unless( $seen{$domain} ) {
* *push( @users, $email );
* *$seen{$domain} = 1;
*}
}

if(@users>0){
*print &div, "The following are uniq users per domain:\n", &div;
*print join( "\n", sort( @users ) ), "\n", &div;
} else {
*print "Sorry. I could not find any email addresses.\n";
}

--
Koncept <<
"The snake that cannot shed its skin perishes. So do the spirits who are
prevented from changing their opinions; they cease to be a spirit."
-Nietzsche
Jul 19 '05 #1
0 3128

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Asha | last post by:
hello... i'm uploading data from an excel file to the server, and to check the data values; i loop though excel file row by row and compare the value with database value. if anything does not...
13
by: Jeff Davis | last post by:
Right now performance isn't a problem, but this question has me curious: Let's say I have a shopping cart system where there is a "products" table that contains all possible products, and an...
5
by: manmit.walia | last post by:
Hello All, I am stuck on a conversion problem. I am trying to convert my application which is written in VB.NET to C# because the project I am working on currently is being written in C#. I tried...
2
by: eric.houghland | last post by:
Hello, I've read quite a bit about implementing this interface in .NET and believe I have a good start. I am able to use StgIsStorageFile, StgCreateStorage and StgOpenStorage. I am now...
8
by: skumar434 | last post by:
i need to store the data from a data base in to structure .............the problem is like this ....suppose there is a data base which stores the sequence no and item type etc ...but i need only...
11
by: Alan Mailer | last post by:
A project I'm working on is going to use VB6 as a front end. The back end is going to be pre-existing MS Access 2002 database tables which already have records in them *but do not have any...
9
by: MrHelpMe | last post by:
Hello again experts, I have successfully pulled data from an LDAP server and now what I want to do is drop the data into a database table. The following is my code that will insert the data but...
3
by: sunbeam | last post by:
Short Description of the Project: we developed a e-learning system for our students. each student has a unique username/password to view the modules he/she should view and nothing more. since we...
1
by: duane.lortie | last post by:
I'm writing a routine that fetches XML and attempts to parse some values from it. A condensed entry node of the XML looks like this .. <entry> <title>Some title</title> <author>...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.