[perl #7911] no warning for useless /d in tr/0-9//d
authorreneeb <unknown>
Mon, 17 Nov 2008 06:13:57 +0000 (22:13 -0800)
committerSteve Peters <steve@fisharerojo.org>
Tue, 25 Nov 2008 03:51:41 +0000 (03:51 +0000)
From: "reneeb via RT" <perlbug-followup@perl.org>
Message-ID: <rt-3.6.HEAD-10965-1226931231-1833.7911-15-0@perl.org>

p4raw-id: //depot/perl@34905

op.c
pod/perldiag.pod
t/lib/warnings/op

diff --git a/op.c b/op.c
index b679835..10c1fc9 100644 (file)
--- 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
index 03a5ebe..fd2844f 100644 (file)
@@ -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
index 9740e39..cc968c7 100644 (file)
@@ -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' ;