In perl.git, the branch blead has been updated <http://perl5.git.perl.org/perl.git/commitdiff/ccaaf480260ac57f0cc2c88d2a20a0a8e06cc550?hp=ffedb8cac4cef8f45c3d8879ddb708dc35dddd80>
- Log ----------------------------------------------------------------- commit ccaaf480260ac57f0cc2c88d2a20a0a8e06cc550 Author: Father Chrysostomos <[email protected]> Date: Sat Feb 12 12:20:52 2011 -0800 Clarify perldiag/Ambiguous use of %c{%s%s} ${foo[2]} only warns with built-in keywords. (See the source in toke.c:S_scan_ident which uses keyword().) The suggested use of $foo[2] instead of ${foo[2]} does not always work. I also added an âandâ to clarify the existing text. M pod/perldiag.pod commit 3303f755f725e8e6bda8938fabd6f02f2488a668 Author: Father Chrysostomos <[email protected]> Date: Sat Feb 12 10:00:25 2011 -0800 Clean up perldiag/Ambiguous use resolved as operator This entry was missing some words. I supplied them, fixed spelling mistakes, and reflowed it to look good under -Mdiagnostics. M pod/perldiag.pod ----------------------------------------------------------------------- Summary of changes: pod/perldiag.pod | 31 +++++++++++++++++++++---------- 1 files changed, 21 insertions(+), 10 deletions(-) diff --git a/pod/perldiag.pod b/pod/perldiag.pod index aa5b04f..fd6f17c 100644 --- a/pod/perldiag.pod +++ b/pod/perldiag.pod @@ -103,11 +103,12 @@ a missing quote, operator, parenthesis pair or declaration. =item Ambiguous use of %c resolved as operator %c (W ambiguous) C<%>, C<&>, and C<*> are both infix operators (modulus, -bitwise and, and multpication), and you said something like C<*foo * -foo> that might be interpreted as either of them. We assumed you -meant the infix operator, but please try to make it more clear -- in -the example given, you might write C<*foo * foo()> if you really meant -to multiply a glob by the result of calling a function. +bitwise and, and multiplication) I<and> initial special characters +(denoting hashes, subroutines and typeglobs), and you said something +like C<*foo * foo> that might be interpreted as either of them. We +assumed you meant the infix operator, but please try to make it more +clear -- in the example given, you might write C<*foo * foo()> if you +really meant to multiply a glob by the result of calling a function. =item Ambiguous use of %c{%s} resolved to %c%s @@ -120,11 +121,21 @@ and a function with the same name, and save yourself a lot of trouble. =item Ambiguous use of %c{%s%s} resolved to %c%s%s -(W ambiguous) You wrote something like C<${foo[2]}>, which might be -looking for element number 2 of the array named C<@foo>, in which case -please write C<$foo[2]>, or you might have meant to pass an anonymous -arrayref to the function named foo, then do a scalar deref on the -value it returns. If you meant that, write C<${foo([2])}>. +(W ambiguous) You wrote something like C<${foo[2]}> (where foo +represents the name of a Perl keyword), which might be looking for +element number 2 of the array named C<@foo>, in which case please write +C<$foo[2]>, or you might have meant to pass an anonymous arrayref to +the function named foo, and then do a scalar deref on the value it +returns. If you meant that, write C<${foo([2])}>. + +In regular expressions, the C<${foo[2]}> syntax is sometimes necessary +to disambiguate between array subscripts and character classes. +C</$length[2345]/>, for instance, will be interpreted as C<$length> +followed by the character class C<[2345]>. If an array subscript is what +you want, you can avoid the warning by changing C</${length[2345]}/> +to the unsightly C</${\$length[2345]}/>, by renaming your array to +something that does not coincide with a built-in keyword, or by +simply turning off warnings with C<no warnings 'ambiguous';>. =item Ambiguous use of -%s resolved as -&%s() -- Perl5 Master Repository
