in reply to Re: Reading Text from file and reorganization
in thread Reading Text from file and reorganization

sorry for the lack of information. Here is some more.
The text is at the top of the file and goes down the page in a single column. So I need for every even entry of the file to be on the right side of the ode entry. Like so:

dm1w50
5.5.1

Should look like this:
dm1w50 5.5.1

This should continue until the end of file. I want to write this back to a new file stored in the same location as the old file..
I;m still trying to decide if I should do this as a while loop or a foreach loop. I'm currently looking through books trying to make my decision.
The file looks like the example above but just a lot more entries.
curtisb
  • Comment on Re: Re: Reading Text from file and reorganization

Replies are listed 'Best First'.
Re: Re: Re: Reading Text from file and reorganization
by rchiav (Deacon) on May 08, 2001 at 00:56 UTC
    What I'd do is the following..
    #!/usr/bin/perl -w use strict; my @newfile; open (FH, "./testfile"); while (<FH>) { chomp; push @newfile, $_.' '.<FH>; } close FH;
    Here's what's going on. In the while loop I'm getting the 1st line of the file. Then I'm taking the newline character off of it. Then.. I'm taking that line, concatinating it with a space and the next line from the file. NOTE: I'm not stripping the newline character off of that one because you're going to want a new line there :). Then I'm pushing that new string on to an array.

    Now all you have to do is write it out..

    Hope this helps..
    Rich