Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Perl (http://www.go4expert.com/forums/perl/)
-   -   Creating new text file from existing text file content (http://www.go4expert.com/forums/creating-text-file-existing-text-file-t21600/)

denmul 31Mar2010 21:03

Creating new text file from existing text file content
 
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

softmarisaravanan 25Jun2010 19:25

Re: Creating new text file from existing text file content
 
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;


All times are GMT +5.5. The time now is 07:50.