On Oct 4, s wang said:

>i have just started writing some scripts in PERL and i am trying to catch
>a deadline, i really wish i could get some help for this problem. any
>suggestion is greatly appreciated.
>
>i have a set of files with sequences aligned in the following format. i
>wonder how i can eliminate the new line characters within each sequence
>without touching those between sequences?

I think the easiest way is to read in a line, then read the next line.  If
the next line is NOT "\n", then remove the last character from the
previous line:

  open DNA, "< dna.txt" or die "can't read dna.txt: $!";
  open NEW_DNA, "> dna.txt.new" or die "can't write dna.txt.new: $!";

  my $prev = <DNA>;
  until (eof DNA) {
    my $line = <DNA>;
    if ($line ne "\n") {
    chomp $prev if $line ne "\n" and $prev ne "\n";
    print NEW_DNA $prev;
    $prev = $line;
  }
  print NEW_DNA $prev;

  close NEW_DNA;
  close DNA;

  rename "dna.txt" => "dna.txt.old"
    or die "can't rename dna.txt to dna.txt.old: $!";

  rename "dna.txt.new" => "dna.txt"
    or die "can't rename dna.txt.new to dna.txt: $!";

-- 
Jeff "japhy" Pinyan      [EMAIL PROTECTED]      http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
<stu> what does y/// stand for?  <tenderpuss> why, yansliterate of course.
[  I'm looking for programming work.  If you like my work, let me know.  ]


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to