when attempting to print object as in:
print "$response{_content} \n";
printf OUTPUT "$response{_content} \n";
The printf statement generates error "Modification of a read-only value attempted"
It's an intermittent error. Only happens once in a while, but this program needs to be 100% reliable. dang.
It prints fine to STDOUT.
What am I doing wrong? arrgh!
The first argument of printf
is interpreted as output format, not output itself. See perldoc -f printf and man 3 printf for details.
The problem is, printf
might occasionally try to write to its args (this has even been the source of several vulnerabilities in C programs), for instance:
perl -we 'printf "abc%n\n", $_; print "$_\n";'
As you can see, this sets $_
to 3, which is the number of characters written before %n
occurred. Try %n without further args and you'll see the exact error message from OP.
Long story short: use print
unless you really need advanced formatting. Keep first argument to printf
r/o unless you really need even more advanced formatting.
You will need to inspect stdout for the failures. My guess is that once in a while, $response{_content} contains sequences that have special meaning to printf.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With