K
kj
The following demo code causes the warning "Useless use of a constant
in a void context":
use strict;
use warnings;
{ ; package ABC; 1; }
sub foo {}
foo ABC->xyz, 2;
__END__
....because perl parses the last line as
ABC->foo->xyz, 2;
That's annoying enough, but what sends me for a loop is that if I
change the block
{ ; package ABC; 1 }
to
{ ; package PQR; 1 }
now the last line gets parsed as foo( ABC->xyz, 2 ), as any
reasonable, red-blooded parser would.
Now, why on earth would that "package ABC" statement confuse the
parser???
Of course, in this case I can clue in the parser by changing the
last line to
foo( ABC->xyz, 2 );
but this fix makes me uneasy, because it seems fixing the symptom
and not the cause, leaving me wondering about what else in the file
the parser will mess up (in fact this parsing error would have not
have been visible until runtime if the second argument to foo had
been a 1 or a 0 instead of a 2, because perl does not protest when
it finds either of those two values in a void context).
If there's a way to clue-in the parser that is closer to the source
of the error, please let me know.
TIA!
kj
in a void context":
use strict;
use warnings;
{ ; package ABC; 1; }
sub foo {}
foo ABC->xyz, 2;
__END__
....because perl parses the last line as
ABC->foo->xyz, 2;
That's annoying enough, but what sends me for a loop is that if I
change the block
{ ; package ABC; 1 }
to
{ ; package PQR; 1 }
now the last line gets parsed as foo( ABC->xyz, 2 ), as any
reasonable, red-blooded parser would.
Now, why on earth would that "package ABC" statement confuse the
parser???
Of course, in this case I can clue in the parser by changing the
last line to
foo( ABC->xyz, 2 );
but this fix makes me uneasy, because it seems fixing the symptom
and not the cause, leaving me wondering about what else in the file
the parser will mess up (in fact this parsing error would have not
have been visible until runtime if the second argument to foo had
been a 1 or a 0 instead of a 2, because perl does not protest when
it finds either of those two values in a void context).
If there's a way to clue-in the parser that is closer to the source
of the error, please let me know.
TIA!
kj