Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

The solution is that lexical bareword filehandles exist only in the scopes where they are declared.

Single-word package only need prefixes within the same lexical scope as an identically-named filehandle. The use of a filehandle YAML in one block does not affect YAML as a package name outside of that block.

If I write code with a bareword filehandle in a module, I don't know how that module will be used. I don't know when it will be loaded. I don't know what will be loaded before it and I don't know what will be loaded after it.

This proposal is that bareword filehandles in your module would become lexicals, private to your module.

If the parser parses this construct in different ways depending on what's loaded, it's fragile and undecidable.

This is a misunderstanding. Only lexical declarations affect parsing in this proposal, and open BAREWORD,... becomes a lexical declaration. Within the lexical scope of an open YAML,..., YAML would parse as {I/O}YAML and class method calls on YAML would need to be written as ::YAML->method(...) or method ::YAML (...). However, YAML is a bad example here because it has a functional interface, and YAML::DumpFile(...) (for example) is already unambiguous, even if YAML is a lexical filehandle.

Outside of the lexical scope of open YAML,..., YAML remains a "plain" bareword, and close YAML would, for example, parse equivalently to ::YAML->close — that is, as a class method call on package YAML, whether or not YAML is actually loaded. Obviously, executing a method call to an undefined class is an error, but parsing in this proposal does not depend on the set of loaded packages, only the lexical declarations in effect.

After thinking about this a bit more, is your concern what happens if a module attempts to use a bareword filehandle defined elsewhere? The I/O operations on undeclared filehandle BAR would parse as class method calls on package BAR. If BAR does not have methods named for I/O operators, you get an error; if BAR does actually have those methods, they will be called (and they will probably end up throwing errors).


In reply to Re^4: On Backwards Compatibility and Bareword Filehandles by jcb
in thread On Backwards Compatibility and Bareword Filehandles by jcb

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, 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, 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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Domain Nodelet?
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this?Last hourOther CB clients
    Other Users?
    Others studying the Monastery: (3)
    As of 2024-07-20 21:32 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found

      Notices?
      erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.