Re: Why doesn't Perl complain about this bareword?



On 7 Mai, 13:45, "A. Sinan Unur" <1...@xxxxxxxxxxxxxxxxxxx> wrote:
sheinr...@xxxxxxxxxxx wrote innews:764d756d-1678-422e-b813-7b39dedc0e3b@xxxxxxxxxxxxxxxxxxxxxxxxxxx:
On May 7, 6:31 am, benkasminbull...@xxxxxxxxx (Ben Bullock) wrote:
Ronny <ro.naldfi.sc...@xxxxxxxxx> wrote:
By chance I found out that no error is issued on the following
program:

perl -w -e 'use strict; print(Does::Not::Exist,"\n")'

Instead, "Does::Not::Exist" is printed. Shouldn't there be a
warning about
the improper use of a bareword?

It seems to be a bug in Perl.

Even stranger:

scripts>perl -we "use strict; print(Does::Not::Exist);"
Name "Does::Not::Exist" used only once: possible typo at -e line 1.
print() on unopened filehandle Exist at -e line 1.

Note that the issue only arises with print. In the case above,
Does::Not::Exist is being taken to refer to a bareword filehandle Exist
in the package Does::Not. It then seems like print wants to print $_ to
this filehandle.

I think the basic reason is that this is simply a bug, as has been
suggested
already. The Perl parser should recognize it as incorrect bareword,
but doesn't,
so it interprets it more or less "by chance" differently:

In the case of print having only this bareword argument, it seems to
consider
it as a filehandle, but even this would be illegal due to parentheses,
as you
can see when you use a valid file handle:

$ perl -we "use strict; print(STDOUT);"
Use of uninitialized value in print at -e line 1.

And, in the examples I gave (using print and system), the bareword
was clearly taken as a string, not as a filehandle.

I sent a bug report to perl.


Ronald
.



Relevant Pages