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

Hi, I'm writing a short program to look for "\x0D\x0A" in a file, which I can plainly see in UltraEdit. I don't know why, but I can find \x0A by itself, but I can't find \x0D at all. I'm flummoxed!

Replies are listed 'Best First'.
Re: Can't find \x0D
by ikegami (Patriarch) on Feb 07, 2011 at 16:29 UTC
    By default, Perl converts \x0D\x0A to \x0A on read, and \x0A to \x0D\x0A on write on Windows. Use binmode($fh) to work with "binary" data.
      My apologies...this is on an AIX machine. I'm also using binmode. In fact, this is the entire program (just in case I leave any other important facts out! :) ):
      
      #!/usr/bin/perl
      
      use strict;
      
      my $inFile = "TST5.NDM.SB.IOWSFLAT.STMTS.MRDF.TEST";
      my $outFile = "$inFile.out";
      my $buff;
      
      open(INFP, $inFile);
      open(OUTFP, ">$outFile");
      binmode(INFP);
      binmode(OUTFP); 
      
      my $cnt = 1;
      my $matchCnt = 0;
      
      while (read(INFP, $buff, 128)) {
      
        print OUTFP $buff;
        
        my $target = "\x0D";
        if ($buff =~ /$target/) {
          print $buff;
          print "\n found \$target on 'line' $cnt, ";
          print "'" . ord($&) . "', '\x$&'\n";
          ++$matchCnt;
        }
        ++$cnt;
      }
      
      print "found target $matchCnt times\n";
      close (INFP);
      close (OUTFP);
      

        Either you looked at the file using UltraEdit or you're running on AIX. Both aren't possible since UltraEdit doesn't run on AIX.

        Did you perhaps FTP the file between the two systems using ASC mode?

Re: Can't find \x0D
by Anonymous Monk on Feb 07, 2011 at 16:58 UTC
    UltraEdit is probably molesting the file :) od -tacx 1 file or hexdump file
      Oh good lord you're right. I brought it up on the AIX machine using editbin and sure enough, it found \x0A but \x0D isn't there.

      Well, there's a 1/2 day I'll never get back!

      Thanks for everyone's help. I know better next time!

Re: Can't find \x0D
by mvaline (Friar) on Feb 07, 2011 at 17:09 UTC
    Because you're working in binary mode, I would start by confirming the encoding of your file. In particular, if it is a Unicode representation, check whether it is a 8-bit or 16-bit encoding and byte-order.