<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns="http://www.w3.org/TR/REC-html40">

<head>
<meta http-equiv=Content-Type content="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 11 (filtered medium)">
<!--[if !mso]>
<style>
v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style>
<![endif]-->
<style>
<!--
 /* Font Definitions */
 @font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman";}
a:link, span.MsoHyperlink
        {color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-reply;
        font-family:Arial;
        color:navy;}
@page Section1
        {size:8.5in 11.0in;
        margin:1.0in 1.25in 1.0in 1.25in;}
div.Section1
        {page:Section1;}
-->
</style>

</head>

<body lang=EN-US link=blue vlink=purple>

<div class=Section1>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>Get in the habit of putting the following
at the top of every file:<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; use
strict;<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>Try it.&nbsp; It will inform you that you
are implicitly doing just what you claim you are not doing: you have declared
(or, as you put it &#8220;redeclared&#8221;) the variable.&nbsp; &#8220;Use
strict&#8221; will protest because implicit declarations are often an accident;
which is clearly appropriate for your case.<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>By the way, I take exception to your
statement &nbsp;&#8220;. . . should make it global across all name spaces.&#8221;&nbsp;
No such concept exists in Perl.&nbsp; You declared the variable to be in the &#8220;main&#8221;
namespace; which you seemingly understood when you used &#8220;$::c&#8221;, the
naked double-colon being an alias for &#8220;main::&#8221;.&nbsp; &nbsp;The
package &#8220;main&#8221; is in force until you declare otherwise.<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>Alexander Danel<o:p></o:p></span></font></p>

<div>

<div class=MsoNormal align=center style='text-align:center'><font size=3
face="Times New Roman"><span style='font-size:12.0pt'>

<hr size=2 width="100%" align=center tabindex=-1>

</span></font></div>

<p class=MsoNormal><b><font size=2 face=Tahoma><span style='font-size:10.0pt;
font-family:Tahoma;font-weight:bold'>From:</span></font></b><font size=2
face=Tahoma><span style='font-size:10.0pt;font-family:Tahoma'> chicago-talk-bounces+danel=speakeasy.net@pm.org
[mailto:chicago-talk-bounces+danel=speakeasy.net@pm.org] <b><span
style='font-weight:bold'>On Behalf Of </span></b>Mithun Bhattacharya<br>
<b><span style='font-weight:bold'>Sent:</span></b> Wednesday, March 03, 2010
8:20 PM<br>
<b><span style='font-weight:bold'>To:</span></b> chicago-talk@pm.org<br>
<b><span style='font-weight:bold'>Subject:</span></b> [Chicago-talk] Global
variable behavior</span></font><o:p></o:p></p>

</div>

<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'><o:p>&nbsp;</o:p></span></font></p>

<div>

<div>

<p class=MsoNormal><font size=3 face=Arial><span style='font-size:12.0pt;
font-family:Arial'>Hi Everyone,<br>
<br>
A piece of my code is behaving in a way I didn't expect and I was hoping
someone could enlighten me as to why..<br>
</span></font><br>
-------------------------------------<br>
<font size=2><span style='font-size:10.0pt'>$ cat a.pl <br>
push @INC, '.';<br>
<br>
our $c = 15;<br>
<br>
require newbie;<br>
</span></font>-------------------------------------<br>
<font size=2><span style='font-size:10.0pt'>$ cat newbie.pm <br>
package newbie;<br>
<br>
print &quot;first attempt: &quot; . $c . &quot;\n&quot;;<br>
print &quot;second attempt: &quot; . $::c . &quot;\n&quot;;<br>
<br>
1;<br>
</span></font>-------------------------------------<br>
<font size=2><span style='font-size:10.0pt'>$ perl a.pl <br>
first attempt: <br>
second attempt: 15</span></font><br>
-------------------------------------<br>
<font face=Arial><span style='font-family:Arial'><br>
The way I see it the </span></font><font face="Courier New"><span
style='font-family:"Courier New"'>our</span></font><font face=Arial><span
style='font-family:Arial'> in </span></font><font face="Courier New"><span
style='font-family:"Courier New"'>a.pl</span></font><font face=Arial><span
style='font-family:Arial'> should make it global across all namespaces. The
second attempt does seem to say that did take place. What I am not sure is why
the </span></font><font face="Courier New"><span style='font-family:"Courier New"'>$c</span></font><font
face=Arial><span style='font-family:Arial'> variable has become local in scope
even though I haven't re-declared or redefined it in any way inside </span></font><font
face="Courier New"><span style='font-family:"Courier New"'>newbie.pm</span></font><font
face=Arial><span style='font-family:Arial'>.<br>
<br>
<br>
<br>
<br>
- Mithun</span></font><o:p></o:p></p>

</div>

</div>

<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'><o:p>&nbsp;</o:p></span></font></p>

</div>

</body>

</html>