sv_pos_u2b(sv, &pos, &rem);
tmps += pos;
sv_setpvn(TARG, tmps, rem);
- if (lvalue) { /* it's an lvalue! */
+ if (repl)
+ sv_insert(sv, pos, rem, repl, repl_len);
+ else if (lvalue) { /* it's an lvalue! */
if (!SvGMAGICAL(sv)) {
if (SvROK(sv)) {
STRLEN n_a;
LvTARGOFF(TARG) = pos;
LvTARGLEN(TARG) = rem;
}
- else if (repl)
- sv_insert(sv, pos, rem, repl, repl_len);
}
SPAGAIN;
PUSHs(TARG); /* avoid SvSETMAGIC here */
#!./perl
-print "1..106\n";
+print "1..108\n";
#P = start of string Q = start of substr R = end of substr S = end of string
eval 'substr($a,0,0,"") = "abc"';
print "not " unless $@ && $@ =~ /Can't modify substr/ && $a eq "foo";
print "ok 106\n";
+
+$a = "abcdefgh";
+print "not " unless sub { shift }->(substr($a, 0, 4, "xxxx")) eq 'abcd';
+print "ok 107\n";
+print "not " unless $a eq 'xxxxefgh';
+print "ok 108\n";