Hello:
I have two lists of emails saved in flat files one email per line.
My script removes the emails in list 2 if they are present in list 1. Then reprints the email list, one email per line, back into list 2 but without the weeded out emails.
Except that when reprinting back to list 2 the order is random and I want to preserve the same order in which the emails were at first.
EXAMPLE:
if in email list 1 I have:
email_02@server.com
email_04@server.com
email_06@server.com
email_08@server.com
email_10@server.com
and if in email list 2 I have:
email_01@server.com
email_02@server.com
email_03@server.com
email_04@server.com
email_05@server.com
email_06@server.com
email_07@server.com
email_08@server.com
email_09@server.com
email_10@server.com
I want to end up with:
email_01@server.com
email_03@server.com
email_05@server.com
email_07@server.com
email_09@server.com
But Im getting :
email_09@server.com
email_03@server.com
email_07@server.com
email_05@server.com
email_01@server.com
Here is my script: - foreach (@All_Emails_1) {
-
chomp;
-
-
if( /\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,6}/ ){
-
$valid_emails{$_} = '1';
-
-
}
-
}
-
foreach(@All_Emails_2){
-
chomp;
-
if( $valid_emails{$_} eq '1' ){
-
print"<B>($valid_emails{$_}) ($_)<br>";
-
delete($valid_emails{$_});
-
push @repeated_emails,$_;
-
}
-
}
-
my @New_All_Emails_1 = keys(%valid_emails);
-
-
-
$Back_Up_Emails_1 = 'All_Emails_BKUP.txt';
-
$Old_All_Emails_1 = 'All_Emails_1.txt';
-
$New_All_Emails_1 = 'All_Emails_1.txt';
-
-
rename($Old_All_Emails_1, $Back_Up_Emails_1)|| die print"Cant rename $Back_Up_Emails_1";
-
-
open (EMAILLIST, ">>$New_All_Emails_1") || die print"<br><b>Error: Cant open $New_All_Emails_1";
-
flock (EMAILLIST);
-
foreach $email @New_All_Emails_1){
-
print EMAILLIST "$email\n";
-
}
-
flock (EMAILLIST, 8);
-
close (EMAILLIST);
Thanx for your help
virtualweb
5 1770
I guess my suggestion would be to do a sort: -
foreach $email (sort(@New_All_Emails_1)){
-
print EMAILLIST "$email\n";
-
}
-
I haven't tested it, but that should do what you want. Let us know if it works.
Regards,
Jeff
Hi,
Please try this code. - use strict;
-
my (@list1, @list2, @new_list2);
-
# read from flat files
-
# assume @list1 is from list1.txt
-
open (LIST1, "list1.txt");
-
@list1 = <LIST1>;
-
close(LIST1);
-
-
# assume @list2 is from list2.txt
-
open (LIST2, "list2.xt");
-
@list2 = <LIST2>;
-
close(LIST2);
-
-
foreach my $email (@list2) {
-
my @exists = grep { $_ eq $email } @list1;
-
push @new_list2, $email unless @exists > 0;
-
}
-
-
# write @new_list2 to list2.txt
-
open(NEW_LIST2, ">list2.txt");
-
foreach (@new_list2) {print NEW_LIST2 $_."\n";}
-
close(NEW_LIST2);
Regards,
Mohan
RonB 589
Expert Mod 512MB - #!/usr/bin/perl
-
-
use strict;
-
use warnings;
-
use Data::Dumper;
-
-
my %list1;
-
-
open my $ilst1, '<', 'list1.txt' or die $!;
-
while (<$list1>) {
-
chomp;
-
$list1{$_}++;
-
}
-
close $list1;
-
-
my @filtered;
-
open my $list2, '<', 'list2.txt' or die $!;
-
while (<$list2>) {
-
chomp;
-
push(@filtered, $_) unless exists $list1{$_};
-
}
-
close $list2;
-
-
print Dumper \@filtered;
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Adam Hartshorne |
last post by:
As a result of a graphics based algorihtms, I have a list of indices to
a set of nodes.
I want to efficiently identify any node indices that are stored multiple
times in the array and the...
|
by: mps |
last post by:
Suppose.....
arr = Array("only","a","test");
ArrayVar = "arr";
alert(ArrayVar);
This the simplyfied version of my problem.. (alerting 'undefined' instead of
'only'...)
|
by: Abby Lee |
last post by:
I've created the following array and want to be able to process each
indivisual object whenever my function is called. Is this best done
with a "foreach"? I don't see a foreach in my javascript...
|
by: TTroy |
last post by:
Hello, I'm relatively new to C and have gone through more than 4 books
on it. None mentioned anything about integral promotion, arithmetic
conversion, value preserving and unsigned preserving. ...
|
by: yeti349 |
last post by:
Hi, I'm using the following code to retrieve data from an xml file and
populate a javascript array. The data is then displayed in html table
form. I would like to then be able to sort by each...
|
by: BobRoyAce |
last post by:
I have a class that has several Subs that do DB things, some of which
require the same set of parameters to be passed to a stored procedure.
One class has 12 parameters and part of code used to...
|
by: quiz123 |
last post by:
Hi folks,
I have a problem. my function call is
void Rotate_n(int array, int arraySize,int n);
//precondition: arraysize>=1 && n>=0 && n<=arraySize
//post condition: Values in the arrary are...
|
by: Clive Green |
last post by:
Hello peeps,
I am using PHP 5.2.2 together with MP3_Id (a PEAR module for reading and
writing MP3 tags). I have been using PHP on the command line (Mac OS X
Unix shell, to be precise), and am...
|
by: Neil Chambers |
last post by:
I'm currently using multidimensional arrays in PoSH by assigning values
to index positions. I'm doing this because AFAIK there is no way to
initialise an array simply with the 'number' of...
|
by: sophia.agnes |
last post by:
Dear all,
I was going through the book "C a software engineering approach by
darnell & Margolis" there was a section named sign preserving vs value
preserving
it is as follows
sign...
|
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,...
|
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$) {
}
...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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...
|
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,...
|
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...
| |