Change 34905 by [EMAIL PROTECTED] on 2008/11/25 03:51:41
Subject: [perl #7911] no warning for useless /d in tr/0-9//d
From: "reneeb via RT" <[EMAIL PROTECTED]>
Date: Mon, 17 Nov 2008 06:13:57 -0800
Message-ID: <[EMAIL PROTECTED]>
Affected files ...
... //depot/perl/op.c#1023 edit
... //depot/perl/pod/perldiag.pod#502 edit
... //depot/perl/t/lib/warnings/op#38 edit
Differences ...
==== //depot/perl/op.c#1023 (text) ====
Index: perl/op.c
--- perl/op.c#1022~34886~ 2008-11-18 12:32:23.000000000 -0800
+++ perl/op.c 2008-11-24 19:51:41.000000000 -0800
@@ -3451,6 +3451,15 @@
}
}
}
+
+ 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
==== //depot/perl/pod/perldiag.pod#502 (text) ====
Index: perl/pod/perldiag.pod
--- perl/pod/perldiag.pod#501~34830~ 2008-11-13 02:57:27.000000000 -0800
+++ perl/pod/perldiag.pod 2008-11-24 19:51:41.000000000 -0800
@@ -3654,6 +3654,12 @@
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 @@
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
==== //depot/perl/t/lib/warnings/op#38 (text) ====
Index: perl/t/lib/warnings/op
--- perl/t/lib/warnings/op#37~33309~ 2008-02-14 07:14:36.000000000 -0800
+++ perl/t/lib/warnings/op 2008-11-24 19:51:41.000000000 -0800
@@ -551,7 +551,7 @@
# op.c
#
use warnings 'misc' ;
-my $a ; my @a = () ; my %a = () ; my $b = [EMAIL PROTECTED] ; my $c = \%a ;
+my $a ; my @a = () ; my %a = () ; my $b = [EMAIL PROTECTED] ; my $c = \%a ;my
$d = 'test';
@a =~ /abc/ ;
@a =~ s/a/b/ ;
@a =~ tr/a/b/ ;
@@ -564,9 +564,11 @@
%$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 = [EMAIL PROTECTED] ; my $c = \%a ;
+my $a ; my @a = () ; my %a = () ; my $b = [EMAIL PROTECTED] ; my $c = \%a ; my
$d = 'test';
@a =~ /abc/ ;
@a =~ s/a/b/ ;
@a =~ tr/a/b/ ;
@@ -579,6 +581,8 @@
%$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 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' ;
End of Patch.