Jeff Westman wrote:
> I inherited this script, whose code is as follows:
>
> #!/usr/local/bin/perl -w
> ...
> # 'while' starts on line 42
> while (($app_key, $app_value) = each %app_file_count) {
> delete ($app_file_count{$app_key});e
> }
>
> What is the "hanging 'e' on line 43? It is not a subroutine call,
> and there is no terminating semi-colon (';'). Yet, when I do a
> syntax check, I get:
>
> $ perl -c myscript.pl
> Unquoted string "e" may clash with future reserved word at my line 44.
> Useless use of a constant in void context at my line 43. myscript.pl
> syntax OK
>
>
> I'm confused why this is passing a syntax check. This script runs in
> production (without the warning flag).
>From perldoc perldata:
A word that has no other interpretation in the grammar
will be treated as if it were a quoted string. These are
known as "barewords". As with filehandles and labels, a
bareword that consists entirely of lowercase letters risks
conflict with future reserved words, and if you use the
"use warnings" pragma or the -w switch, Perl will warn you
about any such words. Some people may wish to outlaw
barewords entirely. If you say
use strict 'subs';
then any bareword that would NOT be interpreted as a sub-
routine call produces a compile-time error instead. The
restriction lasts to the end of the enclosing block. An
inner block may countermand this by saying "no strict
'subs'".
So the e is a bareword. Adding 'use strict' is the cure for this. I strongly
suspect the e is just a typo; since it's in a statement by itself, it has no
side effects, so the script has always worked.
>From perldoc perlsyn:
Simple statements
The only kind of simple statement is an expression evalu-
ated for its side effects. Every simple statement must be
terminated with a semicolon, unless it is the final state-
ment in a block, in which case the semicolon is optional.
So no syntax error about a missing semicolon, because it's the last
statement in the block.
Also, for fun, try running this portion of the script through:
perl -c -MO=Deparse myscript.pl
You'll see the following:
while (($app_key, $app_value) = each %app_file_count) {
delete $app_file_count{$app_key};
'???';
}
The literal in void context into '???' to show you that it's a useless
statement. (From perldoc B::Deparse, '???' indicates a constant that has
been optimized away).
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]