Re: Why doesn't Perl complain about this bareword?
- From: sheinrich@xxxxxxxxxxx
- Date: Thu, 8 May 2008 02:26:30 -0700 (PDT)
On May 7, 9:21 pm, "A. Sinan Unur" <1...@xxxxxxxxxxxxxxxxxxx> wrote:
sheinr...@xxxxxxxxxxx wrote in news:41f43d75-d4cb-4633-95a9-
e5b76af6a...@xxxxxxxxxxxxxxxxxxxxxxxxxxxx:
On May 7, 1:45 pm, "A. Sinan Unur" <1...@xxxxxxxxxxxxxxxxxxx> wrote:
...
Note the following cases:
C:\t> perl -w -Mstrict -e "print Does,Not,Exist, qq{\n}"
No comma allowed after filehandle at -e line 1.
In this case, Does has a valid interpretation as a
bareword filehandle. Thus, strict does not kick in.
But why is the first argument being taken here for a filehandle, in
spite of the comma, and not considered as namespace, as in your other
example?
Well, it is a bareword. The most natural use of a bareword found
following print is to specify a filehandle in the current package.
The alternative to giving an error message would have been to print Does
which is not what the programmer wanted in 99.9999% of cases of a
bareword following a print followed by a comma.
It seems like only Strings containing :: (or ' ) qualify as possible
package names.
No. DoESnoTExiST is also a valid package name. However, only ' and ::
can be used as separators in a package name.
That was my point above. (At least I meant it to be ;-)
And because of that I expected Perl to show the same behaviour,
regardless of :: or '.
As we both agree and leaving the comma aside, the first argument could
be a filehandle, a package name or a bareword, just from the look at
it. '::' doesn't change that.
IMHO the actual nature of the beast (or programmer's intention) cannot
be guessed from a following comma but must be determined by a look
into the symbol table.
And if this fails it has to be a bareword and appropriate warning
should be given.
BTW, it could also be a subroutine (with or without a comma
following).
C:\t>perl -w -Mstrict -e "sub DoesExist {} print DoesExist, qq{\n}"
C:\t>perl -w -Mstrict -e "sub DoesExist {} print DoesExist qq{\n}"
C:\t>perl -w -Mstrict -e "print DoesNotExist(), qq{\n}"
Undefined subroutine &main::DoesNotExist called at -e line 1.
Since Perl, in its warnings, never even seems to consider a subroutine
as long as there are no brackets (or '&' sigel), it must already have
taken a look into the symbol table. But why do the warnings elaborate
on all other possibilities?
And why on the other hand, after all other possibilities failed, the
bareword is treated as ordinary string and only if it contains
'::' (the OP's issue).
C:\t>perl -w -Mstrict -e "print DoesNotExist, qq{\n}"
No comma allowed after filehandle at -e line 1.
And why it says "No comma allowed after filehandle" even if it is no
filehandle?
I still find this bahaviour confusing for the user and like Ben Morrow
elsethread, think that it must be caused by some gloomy parts of perl
which we normal users rather shouldn't dare think about.
Cheers, Steffen
.
- References:
- Why doesn't Perl complain about this bareword?
- From: Ronny
- Re: Why doesn't Perl complain about this bareword?
- From: Ben Bullock
- Re: Why doesn't Perl complain about this bareword?
- From: sheinrich
- Re: Why doesn't Perl complain about this bareword?
- From: A. Sinan Unur
- Re: Why doesn't Perl complain about this bareword?
- From: sheinrich
- Re: Why doesn't Perl complain about this bareword?
- From: A. Sinan Unur
- Why doesn't Perl complain about this bareword?
- Prev by Date: Re: Apache vs IIS current directory fro Perl script
- Next by Date: Re: Why doesn't Perl complain about this bareword?
- Previous by thread: Re: Why doesn't Perl complain about this bareword?
- Next by thread: Re: Why doesn't Perl complain about this bareword?
- Index(es):
Relevant Pages
|