<div class="gmail_quote">On Tue, Mar 24, 2009 at 3:37 PM, Jacinta Richardson <span dir="ltr">&lt;<a href="mailto:jarich@perltraining.com.au">jarich@perltraining.com.au</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="im">&gt; I&#39;ll leave the in-depth explaining of the differences between &quot;lexical<br>
&gt; variables&quot; and &quot;package globals&quot; to other sources, but those are the two<br>
&gt; choices. :)<br>
<br>
</div>Technically you&#39;re both wrong.  Declaring variables with &quot;our&quot; does not make
them global.  It makes them package variables.</blockquote><div><br>By that definition, Perl doesn&#39;t implement global variables.<br><br>In Perl, &quot;global variables&quot; are &quot;package variable&quot; are &quot;package globals&quot;.  Package variables are globally accessible but have names partitioned into namespaces (and the namespaces are called &quot;packages&quot;).<br>
<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"> Package variables (those declared with our, or created when you mention a<br>
variable without strict turned on) are visible from the point they are created<br>
to the end of their file; and are accessible to other files as well (when<br>
exported or when their full name is used):<br>
</blockquote><br>$foo::bar is certainly a global variable.  The shorter form, $bar, can sometimes be used to access the global variable.  There are lots of ways to make that happen [&quot;package foo;&quot; w/o &quot;use strict&quot; or w/ &quot;our $bar;&quot; or w/ &quot;use vars qw($bar)&quot; or &quot;bar&quot; actually something special like &quot;ISA&quot;, importing, &quot;bar&quot; actually being a punctuation mark and &quot;foo&quot; being &quot;main&quot;, etc.] and the details of each (especially &quot;our&quot;) can get a bit complicated, even confusing.  But in such cases, $bar is not a different variable from $foo::bar, so $bar is just a convenient name for the global variable, even though whatever trick you used to make the short form usable may not apply globally.<br>
<br></div>Your &quot;visible from the point they are created to the end of their file&quot; is sort-of close to true for most of the tricks for making the short form usable.  The &#39;our&#39; trick is actually lexically scoped (which is what makes &#39;our&#39; such a complex case).  Lots of the other tricks work in any code compiled after the trick was executed (which often seems close to &quot;from here to the end of the file&quot; but is rather different in several ways).<br>
<div> <br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Perl&#39;s true globals are its special variables, which are visible and changable<br>

by everything - whether you want them to be or not.</blockquote><div><br>Um, Perl&#39;s punctuation variables /are/ package variables.  $_ is just short for $main::_.  It is just that $_ is almost always short for $main::_ (even if the current package is not &quot;main&quot;).<br>
<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"> Package variables are often<br>
called globals, but they&#39;re not real globals in the computer science sense.<br>
Close enough though.<br>
</blockquote>
<br>Package variables are visible and changeable by everything, whether you want them to be or not.  The /variables/ are global.  Their long names are global.  Their short names are partitioned into (global) packages (and can be &quot;enabled&quot; in several ways, even including a few ways to enable the short name outside of the package it lives in).  But that doesn&#39;t make the variables &quot;not really globals&quot; even if you add &quot;in the computer science sense&quot;.  Technically.<br>
<br>Calling them &quot;package globals&quot; hints at some of these complexities regarding the names of these global variables.<br><br>Tye<br></div></div>