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

Re: Deprecate barewords?

Thread Next
Aristotle Pagaltzis
November 23, 2015 20:57
Re: Deprecate barewords?
Message ID:
* Eric Brine <> [2015-11-23 19:45]:
> On Mon, Nov 23, 2015 at 9:30 AM, Abigail <> 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

There is something close to a definition in perldata, and it seems to
agree with you at first:

  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.

Aristotle Pagaltzis // <>

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About