Printf "Modification of a read-only error"

when trying to print an object, as in:

print "$response{_content} \n";
printf OUTPUT "$response{_content} \n"; 

The printf statement generates an error "Modifying a read-only value"

This is an intermittent error. It only happens from time to time, but this program should be 100% reliable. Dang.

He prints fine before STDOUT.

What am I doing wrong? Arrgh!

+5
source share
3 answers

The first argument is printfinterpreted as the output format, not the output itself. See perldoc -f printf and man 3 printf for more details .

, printf ( C-), :

perl -we 'printf "abc%n\n", $_; print "$_\n";'

, $_ 3, , %n. % n , OP.

: print, . printf r/o, .

+9

stdout . , $response {_content} , printf.

+2

, printf, :

printf "%-10s $value\n", $label;

-. "x" -, , :

printf "%-10s %s\n", $label, $value;

, , (%) , (&) . , , , -, .

+1

All Articles