summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--op.c3
-rwxr-xr-xt/op/tr.t8
2 files changed, 9 insertions, 2 deletions
diff --git a/op.c b/op.c
index 8125b308ce..85ff67b2b6 100644
--- a/op.c
+++ b/op.c
@@ -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++) {
diff --git a/t/op/tr.t b/t/op/tr.t
index 5cd800f89e..2a0caef1a8 100755
--- a/t/op/tr.t
+++ b/t/op/tr.t
@@ -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";