in reply to auto add a carriage return in front of a line feed, how to delete this auto character.

perldoc -f binmode
  • Comment on Re: auto add a carriage return in front of a line feed, how to delete this auto character.

Replies are listed 'Best First'.
Re^2: auto add a carriage return in front of a line feed, how to delete this auto character.
by xhsoldier (Initiate) on May 21, 2008 at 04:52 UTC
    I use the binmode
    binmode TARGET_FILE; my $outputstring = pack("n*", @list); print TARGET_FILE $outputstring;
    it works well for big-endian
    but when comes to little-endian
    binmode TARGET_FILE; my $outputstring = pack("v*", @list); print TARGET_FILE $outputstring;
    it is still auto add a carriage return in front of a line feed, any ideas?

      but when comes to little-endian [...] it is still auto add a carriage return in front of a line feed

      No it doesn't. Either it adds CRs before LFs or it doesn't. It doesn't know or care how the string was constructed. Something else changed.

      open TARGET_FILE, '>', 'foo' or die; binmode TARGET_FILE; my @list = 10; my $outputstring = pack("v*", @list); print TARGET_FILE $outputstring;
      >perl script.pl >debug script.out -rcx CX 0002 : -d100 l2 0B02:0100 0A 00 .. -q

      PS — Why are you using a global variable (as in TARGET_FILE) for your file handle instead of a lexical? The former hasn't been required for 8 years.