From: Rafael Garcia-Suarez Date: Thu, 6 Dec 2001 11:06:01 +0000 (+0000) Subject: Re: counting tr thinks it's modifying X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=94bfe852f923ec342fb7992aacc667b379dbf1bb;p=p5sagit%2Fp5-mst-13.2.git Re: counting tr thinks it's modifying Message-Id: p4raw-id: //depot/perl@13486 --- diff --git a/op.c b/op.c index 8125b30..85ff67b 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 5cd800f..2a0caef 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";