in reply to Re^3: binmode i/o for perl -pi in-place editing
in thread binmode i/o for perl -pi in-place editing
I still don't do Windows, but I do have a virtual machine with strawberry perl v5.20.2 installed.
Unfortunately, even with the binmode, I found it wasn't sufficient: changing the input file so the first null-separated record (aka "line") has all the various EOL-like sequences showed me wrong: perl -e "binmode STDOUT; $,=qq(\0); print qq(n\nr\rnr\n\rrn\r\nend), qw(encoded file), qq(r:\r\0n:\n\0nr:\n\r\0rn:\r\n), qw(with EOL-like sequences)" > src.bin ⇒ perl -pi pi.pl src.bin & dir src.bin* ⇒ the output is one byte shorter than the input, because the binmode(ARGV) is too late for the first read (as was mentioned in the binmode and one-liners). Also, I'd lost the $/=qq(\0) at some point in the BEGIN block; when I re-inserted that, I found it wasn't working (because the first record had only been reading to the first newline, instead of the first null, and thus masking the fact that binmode wasn't applied for the first read).
In your pi.bat (which you named windows cmd.exe in the OP) file I changed this line:
- perl -pi.orig pi.pl src.bin + perl -Mopen=IO,:raw -pi.orig pi.pl src.bin
and lo! both the original and the modified file have the same size, and identical content but for s/w/v/g. With your src.bin as per the above quotation, running perl -Mopen=IO,:raw -pi.bak -e "s/w/v/g" src.bin again produced the same result.
Either you are getting your test cases mixed up, or something weird is happening. What perl version do you run?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: binmode i/o for perl -pi in-place editing
by pryrt (Abbot) on Dec 09, 2016 at 14:44 UTC |