On Apr 23, Kimberly Schramm said:

>I have a file that is 300+ lines long containing data for an event.  each
>event takes up 6 lines.  I would like to join the 6 lines, so that each
>event is only one line.  Is this possible in perl?

Sure.  Here's how I'd go about doing it:

  open IN, "< file.txt" or die "can't read file.txt: $!";
  open OUT, "> new.txt" or die "can't write new.txt: $!";

  until (eof IN) {
    # read 6 lines from IN and put them in @record
    my @record = map scalar(<IN>), 1 .. 6;

    # remove their newlines
    chomp @record;

    # printing an array in quotes puts a space between each element
    print OUT "@record\n";
  }

  close OUT;
  close IN;

-- 
Jeff "japhy" Pinyan      [EMAIL PROTECTED]      http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
CPAN ID: PINYAN    [Need a programmer?  If you like my work, let me know.]
<stu> what does y/// stand for?  <tenderpuss> why, yansliterate of course.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to