Gossamer Forum
Home : General : Perl Programming :

How can you merge data in file 1 with data in file

Quote Reply
How can you merge data in file 1 with data in file
Hello !
I have 2 files data :

Data file 1 :
abc@mail.com
123@mail.com
sunday@mail.com

Data file 2 :
abc@mail.com
123@mail.com
xyz@mail.com

Hw can you merge data to new file
abc@mail.com
123@mail.com
sunday@mail.com
xyz@mail.com

Please help me out . Thanks


Quote Reply
Re: How can you merge data in file 1 with data in file In reply to
My first thought is that you could use a hash to hold the data.

Code:
open your first file
save the data into an array called @lines
close the file


foreach $line (@lines) {
$output{$line} = 1;
}

open your second file
save the data into an array called @lines
close the file


foreach $line (@lines) {
$output{$line} = 1;
}

open your output file
foreach $key (keys %output) {
print <FILE> $key . "\n"'
}
close your output file
That's how I would do it, although I would probably use some sort of loop to read the two files if I could.

There's probably some really spiffy other way to do it, though. Smile

JPD
http://www.jpdeni.com/dbman/