summaryrefslogtreecommitdiff
path: root/doop.c
diff options
context:
space:
mode:
authorMalcolm Beattie <mbeattie@sable.ox.ac.uk>1997-12-11 11:54:41 +0000
committerMalcolm Beattie <mbeattie@sable.ox.ac.uk>1997-12-11 11:54:41 +0000
commit5d06d08e734fe734c4a9189071f394ad6e9ccaac (patch)
tree13aead60a9b95b42a7180d002d82a517bef8152b /doop.c
parent3fe6f2dcb97acb1a1bb0a27dc5753fbc0548c545 (diff)
downloadperl-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.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/doop.c b/doop.c
index 277f46ef7a..be3e674109 100644
--- a/doop.c
+++ b/doop.c
@@ -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;
}