Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Did you know that open "E", ... works just fine? That seems like it should be a symbolic reference, doesn't it? In other words, yes, stringy file handles suck and use strict doesn't always protect you from them. And that protection is even inconsistant, as you noted.

I'd say you've found a bug. It isn't one I care much about, though. (:

The real solution to your problem is to not simply use things like *E as file handles.

What you want is a reference to a glob (not just a glob) because it is easy to distinguish a reference to a glob from a string while distinguishing a glob from a string is a bit of a trick (I'm not even sure it is always possible). Globs are what Perl4 used in place of references and are really only in Perl5 for backward compatability.

And you want that glob to not currently be in the current symbol table. You can use Symbol's gensym() to get a reference to a glob in that module's symbol table. I tend to prefer:     my $fh= do { local(*FILE); \*FILE }; (which gives you a reference to a glob that was only briefly in the current symbol table) or to use IO::Handle.

Any of these three approaches will prevent the casual string from being successfully used as a file handle. Note that there are lots of other problems with having globs in your current symbol table that are open file handles. For example, open(CGI,... seriously breaks things...

        - tye (but my friends call me "Tye")

In reply to (tye)Re: unexpected close() success on (non-) filehandle by tye
in thread unexpected close() success on (non-) filehandle by mkmcconn

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

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2023-06-07 00:24 GMT
Find Nodes?
    Voting Booth?
    How often do you go to conferences?

    Results (29 votes). Check out past polls.