in reply to Reading Text from file and reorganization

I'm afraid we're going to need more information:

Is this text at the top of the file or could it be anywhere in the file?
Where do you want to concatinate this text? Do you want to write the file back out this way or do you just want to store it internally this way?
Does the file have any type of standard format?
What have you written to attempt to do this?
Can we see the file?

Rich

  • Comment on Re: Reading Text from file and reorganization

Replies are listed 'Best First'.
Re: Re: Reading Text from file and reorganization
by curtisb (Monk) on May 08, 2001 at 00:33 UTC
    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
      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