My guess is because of the map call using a block. Since you have another block, you're referencing the global vars instead of the local vars, because the local vars were in a different block. Just a guess.<br><br><div><span class="gmail_quote">
On 2/8/06, <b class="gmail_sendername">Renegade Muskrat</b> <<a href="mailto:dramaley@spatulacity.cx" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">dramaley@spatulacity.cx</a>> wrote:</span>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
I have a question regarding Perl. I am having trouble figuring out the<br>variable scoping in a script. I've reduced the problem to as simple of<br>a code snippet as i can in order to demonstrate it. In the script below<br>
<br>i believe $test1 and $test2 should be the same. But they are not. Any<br>ideas why not? And how to make both of them display the local<br>variables? Or a better place to ask Perl questions?<br><br><br>The script:<br>
<br>
<br>#!/usr/bin/perl<br>use strict;<br>use warnings;<br><br>our $foo = "global foo";<br><br>{<br> my $foo = "local foo";<br> my $bar = "local bar";<br><br> no strict 'refs';<br> my $test1 = join("\n", map { "$_ => ${$_}"; } qw(foo bar));
<br> my $test2 = join("\n", "foo => $foo", "bar => $bar");<br><br> print "$test1\n----------\n$test2\n";<br>}<br><br><br>The output:<br><br><br>Use of uninitialized value in concatenation (.) or string at
<br>./scratch line 12.<br>foo => global foo<br>bar =><br>----------<br>foo => local foo<br>bar => local bar<br><br>_______________________________________________<br>Cialug mailing list<br><a href="mailto:Cialug@cialug.org" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">
Cialug@cialug.org</a><br><a href="http://cialug.org/mailman/listinfo/cialug" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">http://cialug.org/mailman/listinfo/cialug</a><br></blockquote></div><br>
<br clear="all"><br>-- <br>Tim