There's a point where I have problems, thought
Sorry, it is a rather tricky to get into words, but hopefully this code will illustrate the difference between then the length and the visibility of a scope
sub foo
{ ## start of visible scope
## $x a lexical var only accessable in the *visible* scope
my $x = "a lexical var";
## $y changed for the *length* of the scope
local $y = "a dynamic var";
print "foo(\$x): $x\n";
print "foo(\$y): $y\n";
bar($y);
} ## end of visible scope
sub bar {
## $x is undefined as it is being referenced outside the
## *visible* scope of foo()
## $y is still changed as the scope of foo() has not
## *exitted* yet
print "bar(\$x): $x\n";
print "bar(\$y): $y\n";
}
$y = "a global var";
foo();
## now foo() has exitted $y reverts to it's original value
print "main(\$y): $y\n";
__output__
foo($x): a lexical var
foo($y): a dynamic var
bar($x):
bar($y): a dynamic var
main($y): a global var
HTH
_________ broquaint
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|