1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

Creating new text file from existing text file content

Discussion in 'Perl' started by denmul, Mar 31, 2010.

  1. denmul

    denmul New Member

    Joined:
    Mar 31, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    [FONT=Arial,Helvetica, sans-serif][FONT=Arial,Helvetica, sans-serif]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
    [/FONT]
    [/FONT]
     
  2. softmarisaravanan

    softmarisaravanan New Member

    Joined:
    Jun 25, 2010
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Perl Programmer
    Location:
    chennai
    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;
     

Share This Page