What tobyink demonstrated is that a bareword will act as a procedure call if (and only if) a subroutine of that name is known. Perl's auto-quoting of barewords will only kick in in the absence of such a subroutine. Any kind of explicit quoting, of course, will also avoid procedure calls.

my $object3 = 'Foo::Bar'->new; say ref $object3; # says "Foo::Bar"

So we now have established by different examples that trailing double-colons can act like quoting.

There may be caveats though. In some places where perl looks for barewords, the package-quoted bareword does not seem to lose its bareword-likeness.

use strict; use warnings; package Foo::Bar; package main; print Foo::Bar::; # warns: # Name "Foo::Bar" used only once: possible typo # print() on unopened filehandle Bar print Foo::Bar::, "Baz\n"; # prints Foo::BarBaz

Perl has to distinguish whether print with a single argument is called as print HANDLE or print LIST, and apparently uses a rather simple heuristic for this.

I try to avoid ambiguity with print and always use the print HANDLE LIST syntax for printing to handles.


In reply to Re^2: Bareword Package Names by martin
in thread Bareword Package Names by martin

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.