diff options
author | Malcolm Beattie <mbeattie@sable.ox.ac.uk> | 1997-12-11 11:54:41 +0000 |
---|---|---|
committer | Malcolm Beattie <mbeattie@sable.ox.ac.uk> | 1997-12-11 11:54:41 +0000 |
commit | 5d06d08e734fe734c4a9189071f394ad6e9ccaac (patch) | |
tree | 13aead60a9b95b42a7180d002d82a517bef8152b /doop.c | |
parent | 3fe6f2dcb97acb1a1bb0a27dc5753fbc0548c545 (diff) | |
download | perl-5d06d08e734fe734c4a9189071f394ad6e9ccaac.tar.gz |
Stop tr/// from writing to target when only counting.
p4raw-id: //depot/perl@359
Diffstat (limited to 'doop.c')
-rw-r--r-- | doop.c | 12 |
1 files changed, 10 insertions, 2 deletions
@@ -31,7 +31,7 @@ do_trans(SV *sv, OP *arg) register I32 squash = op->op_private & OPpTRANS_SQUASH; STRLEN len; - if (SvREADONLY(sv)) + if (SvREADONLY(sv) && !(op->op_private & OPpTRANS_COUNTONLY)) croak(no_modify); tbl = (short*)cPVOP->op_pv; s = (U8*)SvPV(sv, len); @@ -52,6 +52,14 @@ do_trans(SV *sv, OP *arg) } s++; } + SvSETMAGIC(sv); + } + else if (op->op_private & OPpTRANS_COUNTONLY) { + while (s < send) { + if (tbl[*s] >= 0) + matches++; + s++; + } } else { d = s; @@ -74,8 +82,8 @@ do_trans(SV *sv, OP *arg) matches += send - d; /* account for disappeared chars */ *d = '\0'; SvCUR_set(sv, d - (U8*)SvPVX(sv)); + SvSETMAGIC(sv); } - SvSETMAGIC(sv); return matches; } |