Creating new text file from existing text file content

denmul's Avatar, Join Date: Mar 2010
Newbie Member
Hi!

Would appreciate some help on the following simple issue:

I have 2 text files, names.txt and numbers.txt. Names contains a list of names and numbers contains a list of numbers. I have successfully managed to open both in my Perl program and output their content to arrays (named names and numbers). I need to create a new file called suppliers.txt containing the names and numbers together on one line in the following format name:number

To clarify, names.txt might have

mark
dave
mike

numbers.txt might have

5465
5345
8456

suppliers needs to have

mark:5465
dave:5345
mike:8456

Any help would be greatly appreciated
0
softmarisaravanan's Avatar, Join Date: Jun 2010
Newbie Member
hi friend,

Sorry for my late reply to you. Just before i see your task so i now send my response to you.i dont know that it will be helped you or not.

Anyway i just share my idea

open (NAME, "c:/name.txt");
while ($line = <NAME>) {
$line =~ s/\n//gs;
push (@name, $line);
}
close NAME;
open (NUM, "c:/num.txt");
while ($line = <NUM>) {
$line =~ s/\n//gs;
push (@num, $line);
}
close NUM;

open (SUP, ">c:/sup.txt");
for ($i=0; $i<=$#name; $i++) {
print SUP $name[$i] . ":" . $num[$i] . "\n";
}
close SUP;