in reply to Re: Problems with Perl 5.8.5 and SuSE 92.
in thread Problems with Perl 5.8.5 and SuSE 92.

Sorry about the lack of information. The data file itself is ~1000 lines of DNA sequence (e.g. NNNNNNAAACCTAGGAATACGCGT) separated by linebreaks. Again, it's very simple code, which is what makes this so frustrating:

#!/usr/bin/perl use warnings; use strict; my $filename = 'T7.fa'; open(DNA, $filename); my @lines = <DNA>; close DNA; chomp(@lines); my $genome = join('',@lines); print "$genome\n";

When I run this, I get no error messages, but $genome only prints out what appears to be a concatenation of the last two lines: roughly NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN. In lieu of join, I tried the dot operator like this:
... # <DNA> opened my $genome = ''; while (<DNA>) { chomp($_); $genome.=$_; } close(<DNA>); print "$genome\n";

This too gives no errors and returns a short string of Ns. When I print $genome after each iteration of the while loop it doesn't seem to be adding to the string, but rather erasing the old string and inserting JUST the current line. As I mentioned before, in Windows, both versions return what I expect...a "paragraph" of ~20000 bases. I DO have the same problem on a SuSE 9.0 installation, which I believe includes 5.8.0, but haven't tried anything earlier. Packages that are obviously Perl-driven all seem to work fine on my machine. Thanks so much!

Replies are listed 'Best First'.
Re^3: Problems with Perl 5.8.5 and SuSE 92.
by ikegami (Patriarch) on Dec 11, 2004 at 23:04 UTC

    I think you have a line seperator problem. DOS lines end with CR LF. Unix lines end with LF. If you're reading a DOS text file in unix, the chomp will remove the LF but leave the CR in, causing every line being printed to apear on top of each other. Try $/ = "\x0D\x0A"; before the read, or try adding $genome =~ s/\x0D//g; or try using the following:

    #!/usr/bin/perl use warnings; use strict; my $filename = 'T7.fa'; open(DNA, $filename); my $genome; { local $/; $genome = <DNA>; } close DNA; $genome =~ s/\x0D\x0A//g; print "$genome\n";
      Thanks ikegami. Your suggestion did the trick! I would have never figured that out on my own.