With regards to not truncating anything accidentally, davido mentioned this excellent suggestion: move the original file out of the way first (e.g. if it's called shock_api.h, call it shock_api.h.bak or similar; there's a built-in called rename to do this), then read in from shock_api.h.bak and write out to shock_api.h.
This solves the simultaneous read/write truncation issue, and creates a backup for you in case things go awry.
| [reply] [d/l] [select] |
| [reply] [d/l] [select] |
Be sure to use strict; and use warnings;—they will catch bugs in your code so you don't have to.
Yeah, but it doesn't actually help catching the bug the OP is struggling with, does it?
Bare filehandles ("FH") are discouraged. Use open(my $fh, "<", $tu), three-argument open.
Bollocks. There's nothing wrong with the filehandle or the open the OP used.
| [reply] |