<?xml version="1.0" encoding="windows-1252"?>
<node id="903112" title="Re^2: A curious case of of my()" created="2011-05-05 06:34:10" updated="2011-05-05 06:34:10">
<type id="11">
note</type>
<author id="510280">
shmem</author>
<data>
<field name="doctext">
&lt;blockquote&gt;&lt;i&gt;$href is empty, since it is not passed into foo. hence @array ends up being a package variable and not a lexical variable. 
&lt;/i&gt;&lt;/blockquote&gt;

&lt;p&gt;
As others have pointed out, that's wrong. [doc://my] creates lexicals at compile time. It doesn't have a [doc://our] fallback. The 'if' modifier with a false condition inhibits the opcode which clears the lexical at runtime.
&lt;/p&gt;

&lt;code&gt;
our @array; # package vaiable
@array = qw( foo bar );

sub foo{
        my $var = shift;
        my $href = shift;
        my @array = $href-&gt;{pass_in} if defined $href and exists $href-&gt;{pass_in};
        push @array, $var;

        print "contents : @array\n";
}

print "outer scope - contents : @array\n";

foo(1);
foo(2);

print "outer scope - contents : @array\n";

__END__
outer scope - contents : foo bar
contents : 1
contents : 1 2
outer scope - contents : foo bar

&lt;/code&gt;
&lt;p&gt;As you can see, the variable @array inside the sub is a lexical.&lt;/p&gt;</field>
<field name="root_node">
897458</field>
<field name="parent_node">
897553</field>
</data>
</node>
