diff options
-rw-r--r-- | op.c | 3 | ||||
-rwxr-xr-x | t/op/tr.t | 8 |
2 files changed, 9 insertions, 2 deletions
@@ -2936,6 +2936,9 @@ Perl_pmtrans(pTHX_ OP *o, OP *expr, OP *repl) if (!squash) o->op_private |= OPpTRANS_IDENTICAL; } + else if (!squash && rlen == tlen && memEQ((char*)t, (char*)r, tlen)) { + o->op_private |= OPpTRANS_IDENTICAL; + } for (i = 0; i < 256; i++) tbl[i] = -1; for (i = 0, j = 0; i < tlen; i++,j++) { @@ -5,7 +5,7 @@ BEGIN { @INC = '../lib'; } -print "1..71\n"; +print "1..72\n"; $_ = "abcdefghijklmnopqrstuvwxyz"; @@ -174,7 +174,7 @@ print (( eval '$1 =~ tr/abcd//' == 3) ? '' : 'not ', "ok 27\n"); print ((eval '"123" =~ tr/12//' == 2) ? '' : 'not ', "ok 28\n"); # 29: test lhs bad if updating -eval '"123" =~ tr/1/1/'; +eval '"123" =~ tr/1/2/'; print (($@ =~ m|^Can't modify constant item in transliteration \(tr///\)|) ? '' : 'not ', "ok 29\n"); @@ -397,3 +397,7 @@ foreach (keys %a) { tr/N/n/; print +($_ eq 'n' ? '' : "not ") . "ok 71\n"; } + +# 72: counting on a constant +$x = eval '"1213" =~ tr/1/1/'; +print $@ || $x != 2 ? "not ok 72\n" : "ok 72\n"; |