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
printfis interpreted as output format, not output itself. See perldoc -f printf and man 3 printf for details.The problem is,
printfmight occasionally try to write to its args (this has even been the source of several vulnerabilities in C programs), for instance:As you can see, this sets
$_to 3, which is the number of characters written before%noccurred. Try %n without further args and you’ll see the exact error message from OP.Long story short: use
printunless you really need advanced formatting. Keep first argument toprintfr/o unless you really need even more advanced formatting.