Make sure that when you say "context", you're not thinking "scalar" and "list" context. Those don't apply here. Read on...
print FOO $bar;
Puts the contents of $bar on the filehandle FOO. We're all clear on that.
print(FOO $bar);
Does exactly the same thing in a nicely Perl 4-ish way. Perl's parser knows that the first argument to print (regardless of the parens) might be a filehandle which won't be comma-separated from the first thing to be printed. Now:
print(Package::FOO $bar);
Falls into the same trap. You're just specifying the package that the filehandle is in. The solutions:
print +(Package::FOO $bar);
The + tells the parser that the parens don't go with the print (and therefore the Package::FOO) and they're just grouping. So the parser isn't looking for a filehandle anymore. The Package::FOO gets used with indirect object syntax.
print(Package::FOO($bar));
The parser doesn't see a first-argument space-separated from the things to be printed and knows that Package::Foo is Something Else. (Later it'll know it's a function call.)
print(&Package::FOO $bar);
Same goes here, the parser doesn't see a filehandle here and knows that it shouldn't go looking here for one.

I hope that helps. More importantly I hope my lack-of-sleep answer didn't cause more questions than answered...


In reply to Re: Re: (jeffa) Re: 'print' puzzle by clintp
in thread 'print' puzzle by John M. Dlugosz

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.