use warnings;
use strict;
use Data::Dumper;
my ($d0, $count);
BEGIN {
$Data::Dumper::Terse=$Data::Dumper::Useqq=1;
$Data::Dumper::Indent=0;
$/=qq(\0);
$main::total = 0;
$main::l = 0;
binmode STDIN;
binmode STDOUT;
};
binmode ${^LAST_FH};
$d0 = Dumper($_);
$main::total += $count = s/w/v/g || 0;
$main::l+=length($_);
printf STDERR qq(%-32s vs %-32s: cnt=%d tot=%d l=%d\n), $d0, Dumper($_), $count, $main::total, $main::l;
####
@set PROMPT=$G
rem create binary file
perl -e "binmode STDOUT; $,=qq(\0); print qq(bin\n), qw(encoded file), qq(r:\r\0n:\n\0nr:\n\r\0rn:\r\n), qw(with EOL-like sequences)" > src.bin
rem process
perl -pi.orig pi.pl src.bin
rem show the file sizes are different
dir src.bin*
rem use xxd.exe from gvim for windows to show hexdump
xxd src.bin.orig
xxd src.bin
@set PROMPT=$P$G
##
##
>rem create binary file
>perl -e "binmode STDOUT; $,=qq(\0); print qq(bin\n), qw(encoded file), qq(r:\r\0n:\n\0nr:\n\r\0rn:\r\n), qw(with EOL-like sequences)" > src.bin
>rem process
>perl -pi.orig pi.pl src.bin
"bin\n\0" vs "bin\n\0" : cnt=0 tot=0 l=5
"encoded\0" vs "encoded\0" : cnt=0 tot=0 l=13
"file\0" vs "file\0" : cnt=0 tot=0 l=18
"r:\r\0" vs "r:\r\0" : cnt=0 tot=0 l=22
"n:\n\0" vs "n:\n\0" : cnt=0 tot=0 l=26
"nr:\n\r\0" vs "nr:\n\r\0" : cnt=0 tot=0 l=32
"rn:\r\n\0" vs "rn:\r\n\0" : cnt=0 tot=0 l=38
"with\0" vs "vith\0" : cnt=1 tot=1 l=43
"EOL-like\0" vs "EOL-like\0" : cnt=0 tot=1 l=52
"sequences" vs "sequences" : cnt=0 tot=1 l=61
>rem show the file sizes are different
>dir src.bin*
Volume in drive C is System
Volume Serial Number is 309C-2FED
Directory of C:\Users\peter.jones\Documents\HX27\LocalDatalogs\Gage\PASS2
12/07/2016 03:11 PM 65 src.bin
12/07/2016 03:11 PM 61 src.bin.orig
2 File(s) 126 bytes
0 Dir(s) 82,748,403,712 bytes free
>rem use xxd.exe from gvim for windows to show hexdump
>xxd src.bin.orig
0000000: 6269 6e0a 0065 6e63 6f64 6564 0066 696c bin..encoded.fil
0000010: 6500 723a 0d00 6e3a 0a00 6e72 3a0a 0d00 e.r:..n:..nr:...
0000020: 726e 3a0d 0a00 7769 7468 0045 4f4c 2d6c rn:...with.EOL-l
0000030: 696b 6500 7365 7175 656e 6365 73 ike.sequences
>xxd src.bin
0000000: 6269 6e0d 0a00 656e 636f 6465 6400 6669 bin...encoded.fi
0000010: 6c65 0072 3a0d 006e 3a0d 0a00 6e72 3a0d le.r:..n:...nr:.
0000020: 0a0d 0072 6e3a 0d0d 0a00 7669 7468 0045 ...rn:....vith.E
0000030: 4f4c 2d6c 696b 6500 7365 7175 656e 6365 OL-like.sequence
0000040: 73 s