<?xml version="1.0" encoding="windows-1252"?>
<node id="756951" title="Re: Scope surprise" created="2009-04-10 20:17:57" updated="2009-04-10 20:17:57">
<type id="11">
note</type>
<author id="218135">
Nkuvu</author>
<data>
<field name="doctext">
&lt;p&gt;If you had &lt;c&gt;use warnings&lt;/c&gt; in the script you'd see something like &lt;c&gt;"my" variable $foo masks earlier declaration in same scope at scriptname.pl line 6.&lt;/c&gt;
&lt;/p&gt;
&lt;p&gt;I'm pretty sure that Perl is parsing the script prior to actually executing it, seeing the second declaration of &lt;c&gt;$foo&lt;/c&gt; which masks the first declaration, and using that second variable in the same scope to actually execute the script. So you're calling the subroutine before defining the second &lt;c&gt;$foo&lt;/c&gt;, meaning you print an uninitialized value.&lt;/p&gt;
&lt;p&gt;You would see the same output if you had a script like&lt;br&gt;
&lt;c&gt;use strict;

foo();
my $foo = 2;

sub foo {
    print "foo: $foo\n";
}&lt;/c&gt;&lt;/p&gt;</field>
<field name="root_node">
756943</field>
<field name="parent_node">
756943</field>
</data>
</node>
