in reply to Why Is Writing to a Binary File so Hard?[SOLVED]
You are converting characters to the integer value of their codepoints with the unpack(), and you end up printing those integers. At some point you need to convert integers back to characters with chr().
The smallest change to fix this problem in your code would probably be to replace the print lines:
# print "$c"; print chr($c); # print $out $c; print $out chr($c);
An alternative would be to make the whole thing much simpler by treating the line directly without converting to integers at all:
while (my $line = <$in>) { $line =~ s/\n/\r/; # replace LF with CR in the line print $out $line; # and output it }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Why Is Writing to a Binary File so Hard?
by NetWallah (Canon) on Feb 01, 2024 at 00:21 UTC | |
by afoken (Chancellor) on Feb 01, 2024 at 09:29 UTC | |
Re^2: Why Is Writing to a Binary File so Hard?
by jmlynesjr (Deacon) on Feb 01, 2024 at 01:07 UTC |