473,659 Members | 2,965 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3146

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

Similar topics

3
1455
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 match i throws an error. this makes it pretty slow if the record is big.. can someone please advice me how to overcome this problem?
13
1654
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 "cart_items" table that stores how many of each product are in each cart. The obvious (or the first thing that came to my mind) would look something like this: create table products (
5
2721
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 my best to convert it, but somehow the app does not work. I am also not getting any errors when I complie thus, letting me know I am on the write track. Basically what I want to do is edit,add,delete, and update an XML file in a DataGrid. Below...
2
6211
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 attempting to create a new storage file and then use CopyTo to copy the contents of a different opened storage file into the new file. I am getting an error: Invalid pointer error. (Exception from HRESULT: 0x80030009 (STG_E_INVALIDPOINTER)) when calling...
8
2736
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 the sequence nos and it should be such that i can access it through the structure .plz help me .
11
4485
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 AutoNumber* fields in them. Correct me if I'm wrong, but I'm assuming this means that I cannot now alter these existing Access tables and change their primary key to an "AutoNumber" type. If I'm right about this, I need some suggestions as to the...
9
2187
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 that has problems. FullName=Request.Form("Name") Email=Request.Form("Email") GivenName=Request.Form("GivenName")
3
5609
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 want to give them the opportunity to run these modules from home as well, we are trying to get the USERNAME/COMPUTERNAME as well, so the students, when they sign up for the modules, they can ONLY run the modules fromhome PC. We found a nice...
1
4386
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> <name>Author</name> </author> <source:resource url="http://somesite.com?tid=123456"/>
0
8335
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8851
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8528
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8627
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4335
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2752
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1976
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1737
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.