What's so wrong with doing open RD, '<', 'file.txt' ?
I was involved with two discussions about this recently, lexical vs. local file handles and Re^2: Summing numbers in a file, so here are my two cents. To summarize the disadvantages of bareword filehandles:
- They don't protect against typos.
- They're package-globals.
- They clash with package names and subs.
- If you do want to localize them, that comes with even more disadvantages.
- Package-global filehandles usually go out of scope much later than lexicals, so the automatic close doesn't really help.
I don't think that bareword filehandles should "never, ever" be used, and removing them would most likely break a lot of CPAN. But IMHO they shouldn't be used in new code, and newcomers should use lexicals instead. My understanding of Perl 7 is that it is an attempt to introduce defaults that are modern and reduce the cognitive load on the coder - sure, you can use bareword filehandles if you know what you're doing and are willing to manually check for all potentially typos and name clashes caused by them. In the beginning, I used to code without strict and warnings, and I can still remember the amount of time I would spend proofreading my code for such issues.
use of barewords as filehandles will be disallowed in perl 7
My understanding of Sawyer's talk is that the new default will be no bareword::filehandles, and you are free to write use bareword::filehandles.
-
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.
|