in reply to Re: binmode i/o for perl -pi in-place editing
in thread binmode i/o for perl -pi in-place editing

Yeah, I ended up using something similar to your non-pi script to actually do the processing yesterday. (And today, I was able to follow shmem's suggestions to get the -pi working)

My searches indicate that debug.exe hasn't shipped with Win7(1,2) (or probably beyond), though it did ship with Windows XP(3). Regardless of normal, my Win7 64bit installation doesn't include it. I just used xxd, because it was faster than rolling my own hex dumper in perl -- though I should have, once I was trying to bring fellow Monks to help me. :-)

I was just using null-separated text for easy-to-create dummy data. Really, it is a binary data format, which can have the bytes 0x0A and 0x0D anywhere (not really functioning as newlines), but occasionally has embedded strings; I was trying to edit some of those occasional strings (and I couldn't get my GnuWin32 sed.exe to do the changes I wanted -- I was probably not escaping something correctly on the command line -- so I switched to perl, because I thought it would be easier (and I wanted to learn more about the -pi options, since I'd never used that combination, I'd normally just rolled my own file loop, like I ended up doing.)

Again, everyone, thanks for your help and suggestions. I've learned more, which is always my goal here.


1 http://superuser.com/questions/510671 /is-there-debug-exe-equivalent-for-windows7: implies it doesn't ship with Win7
2 http://www.computerhope.com/forum/index.php?topic=129058.0: implies it doesn't ship with Win7
3 https://technet.microsoft.com/en-us/library/bb491040.aspx: did ship with XP

Replies are listed 'Best First'.
Re^3: binmode i/o for perl -pi in-place editing
by shmem (Chancellor) on Dec 09, 2016 at 16:38 UTC
    Really, it is a binary data format, which can have the bytes 0x0A and 0x0D anywhere (not really functioning as newlines), but occasionally has embedded strings; I was trying to edit some of those occasional strings...

    Something like that was my very first use of -pi back in the '90s - monkey-patching a different hostid into a binary bound to a specific Sun workstation, when due to sudden death of one machine they had to be transferred to the other which was not licensed. The only other method would have been manipulating the hostid at the OpenBoot PROM, which was deemed too dangerous (and it changes the MAC Address as well).

    Then monkey-patching windows dlls containing incomplete translations (making sure that the replacing string is equal or lower in size as the original, of course)... that type of fun stuff.

    Anyways. I am/was glad I could help ;-)

    perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'