develooper Front page | perl.perl5.porters | Postings from November 2015

Re: Deprecate barewords?

Thread Previous
From:
Abigail
Date:
November 23, 2015 22:10
Subject:
Re: Deprecate barewords?
Message ID:
20151123221037.GC5188@almanda.fritz.box
On Mon, Nov 23, 2015 at 09:57:20PM +0100, Aristotle Pagaltzis wrote:
> * Eric Brine <ikegami@adaelis.com> [2015-11-23 19:45]:
> > On Mon, Nov 23, 2015 at 9:30 AM, Abigail <abigail@abigail.be> wrote:
> > > I use
> > >
> > >     print STDERR "bla bla";
> > >
> > > quite often.
> >
> > Neither "print" nor "STDERR" are barewords in that program. A bareword
> > is an identifier treated as a string since it has no other meaning.
> 
> Nope. I cannot find a definition of the term in the docs right now, but
> perldiag does have this bit:
> 
>   Bareword "%s" not allowed while "strict subs" in use
>       (F) With "strict subs" in use, a bareword is only allowed as
>       a subroutine identifier, in curly brackets or to the left of
>       the "=>" symbol. Perhaps you need to predeclare a subroutine?
> 
> So barewords can (at least) also be subroutine identifiers. Which agrees
> with this bit in perlobj:
> 
>   Because Perl allows you to use barewords for package names and
>   subroutine names, it sometimes interprets a bareword's meaning
>   incorrectly.
> 
> There is something close to a definition in perldata, and it seems to
> agree with you at first:
> 
>   Barewords
>   ---------
>   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. Perl limits barewords (like identifiers) to about 250
>   characters. Future versions of Perl are likely to eliminate these
>   arbitrary limitations.
> 
> But then it immediately proceeds to contradict itself on that narrower
> definition, and sides instead with the rest the documentation:
> 
>   Some people may wish to outlaw barewords entirely. If you say
> 
>       use strict 'subs';
> 
>   then any bareword that would NOT be interpreted as a subroutine 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'".
> 
> Again, then, barewords can be interpreted as subroutine calls.
> 
> I have also heard the term “bareword filehandle” quite a bit in Perl
> circles, but it turns out that this is not to be found in the core POD.
> It only shows up in the docs of some modules and in a few comments in
> the perl sources.


As quoted before, "perldoc -f print" mentions "bareword handle". 
"perldoc -f open" contains the phrase:

    An older style is to use a bareword as the filehandle



Abigail

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About