From 4a0af295990d09b0499eeb3e34fadfd43fb8e1ca Mon Sep 17 00:00:00 2001 From: Steve Hay Date: Sun, 15 Sep 2013 23:39:41 +0100 Subject: [PATCH] perldelta - Update new/changed diagnostics section Also tweak some formatting in perldiag.pod itself. --- pod/perldelta.pod | 97 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- pod/perldiag.pod | 6 ++-- 2 files changed, 99 insertions(+), 4 deletions(-) diff --git a/pod/perldelta.pod b/pod/perldelta.pod index c00a092..4f87193 100644 --- a/pod/perldelta.pod +++ b/pod/perldelta.pod @@ -612,7 +612,49 @@ and New Warnings =item * -XXX L +L + +(F) You used index/value array slice syntax (C<%array[...]>) as the argument to +C. You probably meant C<@array[...]> with an @ symbol instead. + +=item * + +L + +(F) You used key/value hash slice syntax (C<%hash{...}>) as the argument to +C. You probably meant C<@hash{...}> with an @ symbol instead. + +=item * + +L + +(F) The argument to C must be either a hash or array element, such as: + + $foo{$bar} + $ref->{"susie"}[12] + +or a hash or array slice, such as: + + @foo[$bar, $baz, $xyzzy] + @{$ref->[12]}{"susie", "queue"} + +=item * + +L + +(F) The argument to C must be a hash or array element or a subroutine +with an ampersand, such as: + + $foo{$bar} + $ref->{"susie"}[12] + &do_something + +=item * + +L + +(F) The argument to C for C must be a subroutine name, and +not a subroutine call. C will generate this error. =back @@ -628,6 +670,54 @@ L + +(W syntax) There is a possible problem with the mixing of a control flow +operator (e.g. C) and a low-precedence operator like C. Consider: + + sub { return $a or $b; } + +This is parsed as: + + sub { (return $a) or $b; } + +Which is effectively just: + + sub { return $a; } + +Either use parentheses or the high-precedence variant of the operator. + +Note this may be also triggered for constructs like: + + sub { 1 if die; } + +=item * + +L + +(W syntax) In scalar context, you've used an array index/value slice (indicated +by %) to select a single element of an array. Generally it's better to ask for +a scalar value (indicated by $). The difference is that C<$foo[&bar]> always +behaves like a scalar, both in the value it returns and when evaluating its +argument, while C<%foo[&bar]> provides a list context to its subscript, which +can do weird things if you're expecting only one subscript. When called in +list context, it also returns the index (what C<&bar> returns) in addition to +the value. + +=item * + +L + +(W syntax) In scalar context, you've used a hash key/value slice (indicated by +%) to select a single element of a hash. Generally it's better to ask for a +scalar value (indicated by $). The difference is that C<$foo{&bar}> always +behaves like a scalar, both in the value it returns and when evaluating its +argument, while C<@foo{&bar}> and provides a list context to its subscript, +which can do weird things if you're expecting only one subscript. When called +in list context, it also returns the key in addition to the value. + =back =head2 Changes to Existing Diagnostics @@ -657,6 +747,11 @@ string. The message has been changed to read: Additionally, the C<'E-- HERE'> marker in the error will now point to the correct spot in the regex. +=item * + +The "%s "\x%X" does not map to Unicode" warning is now correctly listed as a +severe warning rather than as a fatal error. + =back =head1 Utility Changes diff --git a/pod/perldiag.pod b/pod/perldiag.pod index d1d199a..002834c 100644 --- a/pod/perldiag.pod +++ b/pod/perldiag.pod @@ -1675,7 +1675,7 @@ C. You probably meant C<@hash{...}> with an @ symbol instead. =item delete argument is not a HASH or ARRAY element or slice -(F) The argument to delete() must be either a hash or array element, +(F) The argument to C must be either a hash or array element, such as: $foo{$bar} @@ -1902,7 +1902,7 @@ OS. See L. =item exists argument is not a HASH or ARRAY element or a subroutine -(F) The argument to exists() must be a hash or array element or a +(F) The argument to C must be a hash or array element or a subroutine with an ampersand, such as: $foo{$bar} @@ -1911,7 +1911,7 @@ subroutine with an ampersand, such as: =item exists argument is not a subroutine name -(F) The argument to exists() for C must be a subroutine +(F) The argument to C for C must be a subroutine name, and not a subroutine call. C will generate this error. -- 2.7.4