beetle has asked for the wisdom of the Perl Monks concerning the following question:

Hey all. A recent installation of SuSE 9.2 included Perl 5.8.5, which has been giving me some trouble. Some very simple code that is meant to concatenate ~1000 lines of text from an input file instead produces one line of seemingly random characters. Neither the dot operator nor the join function seem to be working properly. I thought I was going insane, so I tried the very same script on my Windows partition and it worked fine; additionally, join and . are perfectly functional in linux when I test them on shorter LISTS. The @INC array appears to include the proper paths to the Perl libraries. Can anyone suggest another configuration-type check I might make? Thanks so much.

Retitled by davido for improved searching, per consideration.

Replies are listed 'Best First'.
Re: Problems with Perl 5.8.5 and SuSE 92.
by Zaxo (Archbishop) on Dec 11, 2004 at 21:10 UTC

    If you show us the code with warnings on, the data, what you expect, and what you get, we can probably help.

    Otherwise, you're just asking for an ill-informed guess. My first guess is some character encoding problem.

    After Compline,
    Zaxo

      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!

        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";
Re: Problems with Perl 5.8.5 and SuSE 92.
by gaal (Parson) on Dec 11, 2004 at 21:19 UTC
    Zaxo's guess is mine too. Try printing every line as you go. Check what your LANG is set to and what enconding the file is in.

    Did this work on a previous version of perl on your linux machine? Was that a pre-5.8.0 version?