Something that seems to be missed every time this discussion is referenced is that the main purpose of our
is not to replace use vars
, but to serve as a syntactic peg upon which lexically scoped traits can be hung.
The purpose of our
is to provide a lexically scoped view
of a global variable. The variable itself might not be constant, for instance, but I might want to declare it that way for the sake of my own discipline. Beyond that, various forms of allomorphism will only get more important as Perl 6 allows more type and trait declarations within variable and subroutine declarations.
But even leaving allomorphism out of it, traits are becoming much more important in Perl 6. For instance, exported variables in Perl 6 are simply marked with an "is export
" trait rather having to duplicate their names in an @EXPORT_OK
The secondary reason for having a lexically scoped declaration is to limit your exposure to accidental use of the variable. But really, that's just another aspect of
controlling the "view", or non-view, in this case.
I doubt we'll all ever see eye-to-eye on the subject of globals, but at least grant me the privilege of pointing out that, at least in my mind, the feature was added more to future-proof the declaration syntax than out of reaction to use vars. I freely admit that our is of marginal benefit in Perl 5, but I was already thinking ahead to Perl 6 at that point, even if Perl 6 hadn't been named yet. :-)
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>
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
Want more info? How to link or
or How to display code and escape characters
are good places to start.