From: Father Chrysostomos Date: Sat, 16 Nov 2013 23:12:58 +0000 (-0800) Subject: perldiag: \%d better written as $%d X-Git-Tag: upstream/5.20.0~1208^2~29 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c782d7eeebf2d0f63e4373bcef6d31680ef0d3e3;p=platform%2Fupstream%2Fperl.git perldiag: \%d better written as $%d splain can’t necessarily find it if we hard-code the number: $ ./perl -Ilib -Mdiagnostics -we '()="" =~ s/()()/\1/r' \1 better written as $1 at -e line 1 (#1) (W syntax) Outside of patterns, backreferences live on as variables. The use of backslashes is grandfathered on the right-hand side of a substitution, but stylistically it's better to use the variable form because other Perl programmers will expect it, and it works better if there are more than 9 backreferences. $ ./perl -Ilib -Mdiagnostics -we '()="" =~ s/()()/\2/r' \2 better written as $2 at -e line 1. $ %d is more intuitive than %c here, so I used %d in the pod instead of copying the C code that generates it. --- diff --git a/pod/perldiag.pod b/pod/perldiag.pod index 9f07683..53f5e68 100644 --- a/pod/perldiag.pod +++ b/pod/perldiag.pod @@ -489,7 +489,7 @@ occurred. Since the intended environment for the C could not be guaranteed (due to the errors), and since subsequent code likely depends on its correct operation, Perl just gave up. -=item \1 better written as $1 +=item \%d better written as $%d (W syntax) Outside of patterns, backreferences live on as variables. The use of backslashes is grandfathered on the right-hand side of a diff --git a/t/porting/diag.t b/t/porting/diag.t index 8dece71..df6e1b3 100644 --- a/t/porting/diag.t +++ b/t/porting/diag.t @@ -472,7 +472,6 @@ Can't %s script `%s' with ARGV[0] being `%s' Can't %s "%s": %s Can't %s `%s' with ARGV[0] being `%s' (looking for executables only, not found) Can't use string ("%s"%s) as a subroutine ref while "strict refs" in use -\%c better written as $%c Character(s) in '%c' format wrapped in %s chown not implemented! clear %s diff --git a/toke.c b/toke.c index cd653dd..efb6533 100644 --- a/toke.c +++ b/toke.c @@ -3379,6 +3379,7 @@ S_scan_const(pTHX_ char *start) if (PL_lex_inwhat == OP_SUBST && !PL_lex_inpat && isDIGIT(*s) && *s != '0' && !isDIGIT(s[1])) { + /* diag_listed_as: \%d better written as $%d */ Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX), "\\%c better written as $%c", *s, *s); *--s = '$'; break;