use strict; use warnings; use Inline C => <<'__EOI__'; /* Something Perl shouldn't free */ static char s[4] = "\x11\x11\x11\x11"; SV* fetch() { SV* sv = newSV_type(SVt_PV); SvPV_set(sv, s); SvPOK_on(sv); SvLEN_set(sv, 0); SvCUR_set(sv, 4); return newRV_noinc(sv); } __EOI__ my $ref = fetch(); print(unpack('H*', $$ref), "\n"); $$ref = pack('N', 0x22222222); # Bad: Replaces the $ref = fetch(); # PV instead of print(unpack('H*', $$ref), "\n"); # modifying it. substr($$ref, 0, 4, pack('N', 0x33333333)); # OK $ref = fetch(); print(unpack('H*', $$ref), "\n"); substr($$ref, 0, 4) = pack('N', 0x44444444); # OK $ref = fetch(); print(unpack('H*', $$ref), "\n"); substr($$ref, 0) = pack('N', 0x55555555); # OK $ref = fetch(); print(unpack('H*', $$ref), "\n"); vec($$ref, 0, 32) = 0x66666666; # OK $ref = fetch(); print(unpack('H*', $$ref), "\n");