<?xml version="1.0" encoding="windows-1252"?>
<node id="149304" title="Help needed understanding global variables in Perl" created="2002-03-05 03:22:45" updated="2005-08-13 09:50:21">
<type id="115">
perlquestion</type>
<author id="961">
Anonymous Monk</author>
<data>
<field name="doctext">
&lt;p&gt;Hi. I'm a newbie Perl programmer (but a relatively experienced
programmer in C) and I'm having trouble understanding the use of
global variables in Perl. I would appreciate if people could help
me.&lt;/p&gt;

&lt;p&gt;The problem that I'm having is actually very simple: how exactly do
I define (rather than declare) a global variable in Perl? (I know that declaring the variable may be done with &lt;code&gt;use vars&lt;/code&gt;.)&lt;/p&gt;

&lt;p&gt;I see that even under &lt;code&gt;use strict&lt;/code&gt;, I don't have to
declare/define global variables in Perl: I just need to fully qualify
them and they're already there. Is this correct? If it is, then is
there any kind of "super" &lt;code&gt;use strict&lt;/code&gt;, which helps me
catch typos that my programs may have?&lt;/p&gt;

&lt;p&gt;Also, is there any way of defining a variable like C's static
(i.e., a global variable with local scope). I see that Perl's
&lt;code&gt;our&lt;/code&gt; is almost what I want, but the variable declared with
&lt;code&gt;our&lt;/code&gt; in a function is still accessible outside the
function if I use the variable's fully qualified name. I fear that I
don't completely understand &lt;code&gt;our&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;In fact, I have trouble understanding the difference between
&lt;code&gt;our ($i);&lt;/code&gt; and &lt;code&gt;use vars qw($i);&lt;/code&gt; Can anybody
help with the difference? They don't seem different to the eyes of
this poor Perl newbie.&lt;/p&gt;

&lt;p&gt;Thanks in advance for any comments.&lt;/p&gt;
</field>
<field name="reputation">
97</field>
</data>
</node>
