summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--op.c9
-rw-r--r--pod/perldiag.pod12
-rw-r--r--t/lib/warnings/op12
3 files changed, 30 insertions, 3 deletions
diff --git a/op.c b/op.c
index b67983520b..10c1fc9be9 100644
--- a/op.c
+++ b/op.c
@@ -3451,6 +3451,15 @@ Perl_pmtrans(pTHX_ OP *o, OP *expr, OP *repl)
}
}
}
+
+ if(ckWARN(WARN_MISC)) {
+ if(del && rlen == tlen) {
+ Perl_warner(aTHX_ packWARN(WARN_MISC), "Useless use of /d modifier in transliteration operator");
+ } else if(rlen > tlen) {
+ Perl_warner(aTHX_ packWARN(WARN_MISC), "Replacement list is longer than search list");
+ }
+ }
+
if (grows)
o->op_private |= OPpTRANS_GROWS;
#ifdef PERL_MAD
diff --git a/pod/perldiag.pod b/pod/perldiag.pod
index 03a5ebe719..fd2844fd22 100644
--- a/pod/perldiag.pod
+++ b/pod/perldiag.pod
@@ -3654,6 +3654,12 @@ earlier.
numeric field that will never go blank so that the repetition never
terminates. You might use ^# instead. See L<perlform>.
+=item Replacement list is longer than search list
+
+(W misc) You have used a replacement list that is longer than the
+search list. So the additional elements in the replacement list
+are meaningless.
+
=item Reversed %s= operator
(W syntax) You wrote your assignment operator backwards. The = must
@@ -4609,6 +4615,12 @@ must be written as
The <-- HERE shows in the regular expression about
where the problem was discovered. See L<perlre>.
+=item Useless use of /d modifier in transliteration operator
+
+(W misc) You have used the /d modifier where the searchlist has the
+same length as the replacelist. See L<perlop> for more information
+about the /d modifier.
+
=item Useless use of %s in void context
(W void) You did something without a side effect in a context that does
diff --git a/t/lib/warnings/op b/t/lib/warnings/op
index 9740e39b92..cc968c7ed0 100644
--- a/t/lib/warnings/op
+++ b/t/lib/warnings/op
@@ -551,7 +551,7 @@ Useless use of a constant (undef) in void context at - line 8.
# op.c
#
use warnings 'misc' ;
-my $a ; my @a = () ; my %a = () ; my $b = \@a ; my $c = \%a ;
+my $a ; my @a = () ; my %a = () ; my $b = \@a ; my $c = \%a ;my $d = 'test';
@a =~ /abc/ ;
@a =~ s/a/b/ ;
@a =~ tr/a/b/ ;
@@ -564,9 +564,11 @@ my $a ; my @a = () ; my %a = () ; my $b = \@a ; my $c = \%a ;
%$c =~ /abc/ ;
%$c =~ s/a/b/ ;
%$c =~ tr/a/b/ ;
+$d =~ tr/a/b/d ;
+$d =~ tr/a/bc/;
{
no warnings 'misc' ;
-my $a ; my @a = () ; my %a = () ; my $b = \@a ; my $c = \%a ;
+my $a ; my @a = () ; my %a = () ; my $b = \@a ; my $c = \%a ; my $d = 'test';
@a =~ /abc/ ;
@a =~ s/a/b/ ;
@a =~ tr/a/b/ ;
@@ -579,6 +581,8 @@ my $a ; my @a = () ; my %a = () ; my $b = \@a ; my $c = \%a ;
%$c =~ /abc/ ;
%$c =~ s/a/b/ ;
%$c =~ tr/a/b/ ;
+$d =~ tr/a/b/d ;
+$d =~ tr/a/bc/ ;
}
EXPECT
Applying pattern match (m//) to @array will act on scalar(@array) at - line 5.
@@ -593,8 +597,10 @@ Applying transliteration (tr///) to %hash will act on scalar(%hash) at - line 13
Applying pattern match (m//) to %hash will act on scalar(%hash) at - line 14.
Applying substitution (s///) to %hash will act on scalar(%hash) at - line 15.
Applying transliteration (tr///) to %hash will act on scalar(%hash) at - line 16.
+Useless use of /d modifier in transliteration operator at - line 17.
+Replacement list is longer than search list at - line 18.
Can't modify private array in substitution (s///) at - line 6, near "s/a/b/ ;"
-BEGIN not safe after errors--compilation aborted at - line 18.
+BEGIN not safe after errors--compilation aborted at - line 20.
########
# op.c
use warnings 'parenthesis' ;