From: reneeb Date: Mon, 17 Nov 2008 06:13:57 +0000 (-0800) Subject: [perl #7911] no warning for useless /d in tr/0-9//d X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=b08e453b5ad23d251311b831812c303bc4595012;p=p5sagit%2Fp5-mst-13.2.git [perl #7911] no warning for useless /d in tr/0-9//d From: "reneeb via RT" Message-ID: p4raw-id: //depot/perl@34905 --- diff --git a/op.c b/op.c index b679835..10c1fc9 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 03a5ebe..fd2844f 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. +=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. +=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 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 9740e39..cc968c7 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' ;