<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><div style="font-family:tahoma, new york, times, serif;font-size:12pt"><DIV></DIV>
<DIV>apologies - i'll abstain from further coding examples until i am able to compile them. i have no computer at present, and am attempting to get it from memory - kind of a pseudo coder. i did read up a little on the break, and i think my opinion about this was to not use global variables, but if they couldn't be avoided, use package variables instead. </DIV>
<DIV> </DIV>
<DIV>again, my apologies to the list.<BR> </DIV>---<BR>Mark Mertel<BR>206.441.4663<BR>mark.mertel@yahoo.com<BR>http://www.linkedin.com/in/markmertel<BR>http://www.seattlejobs.com/13147468
<DIV><BR></DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: tahoma, new york, times, serif"><BR>
<DIV style="FONT-SIZE: 10pt; FONT-FAMILY: arial, helvetica, sans-serif"><FONT face=Tahoma size=2>
<HR SIZE=1>
<B><SPAN style="FONT-WEIGHT: bold">From:</SPAN></B> Ronald J Kimball <rjk-spug@tamias.net><BR><B><SPAN style="FONT-WEIGHT: bold">To:</SPAN></B> spug-list@pm.org<BR><B><SPAN style="FONT-WEIGHT: bold">Sent:</SPAN></B> Tuesday, March 24, 2009 1:37:33 PM<BR><B><SPAN style="FONT-WEIGHT: bold">Subject:</SPAN></B> Re: SPUG: Confusing behaivior with exported variables<BR></FONT><BR>On Tue, Mar 24, 2009 at 12:25:39PM -0700, Mark Mertel wrote:<BR>><BR>> It does work:<BR>><BR>> package Foo;<BR>> my $bar = "foo bar\n";<BR>> 1;<BR>> ...<BR>><BR>> use Foo;<BR>> use strict;<BR>><BR>> print $Foo::bar; # prints 'foo bar'<BR>><BR>> print $bar; # should throw an error<BR><BR>Did you actually execute this code? It /does not/ do what you say it does.<BR><BR>It would be a very good idea for you to take the time to understand how<BR>my()/our() and lexical/package variables actually work before you spread<BR>more
misinformation on this subject.<BR><BR>Variables declared with my() are lexically scoped. They are not stored in<BR>the symbol table. They are accessible only from within that lexical scope.<BR><BR>Variables declared with our() are package variables. They are stored in<BR>the symbol table. They are accessible globally, but may need to be fully<BR>qualified.<BR><BR>package Foo;<BR>use strict;<BR><BR>{<BR> my $foo = 'foo'; # sets lexical $foo<BR><BR> print "$foo\n"; # prints 'foo'<BR>}<BR><BR>#print "$foo\n"; # error under use strict, prints undef otherwise<BR><BR>{<BR> my $foo; # a different lexical $foo<BR> print "$foo\n"; # prints undef<BR>}<BR><BR>{<BR> our $bar = 'bar'; # sets $Foo::bar<BR> print "$bar\n"; # prints 'bar'<BR>}<BR><BR>#print "$bar\n"; # error under use strict, prints
'bar' otherwise<BR>print "$Foo::bar\n"; # prints 'bar'<BR><BR>{<BR> our $bar; # same $Foo::bar<BR> print "$bar\n"; # prints 'bar'<BR>}<BR><BR>Ronald<BR>_____________________________________________________________<BR>Seattle Perl Users Group Mailing List<BR> POST TO: <A href="mailto:spug-list@pm.org" ymailto="mailto:spug-list@pm.org">spug-list@pm.org</A><BR>SUBSCRIPTION: http://mail.pm.org/mailman/listinfo/spug-list<BR> MEETINGS: 3rd Tuesdays<BR> WEB PAGE: http://seattleperl.org/<BR></DIV></DIV></div><br>
</body></html>