Roger has asked for the wisdom of the Perl Monks concerning the following question:
I expected the following result:use strict; my $k = 1; print "wanted: \$k = $k, got " . InvestigateValue() . "\n"; my $k = 2; print "wanted: \$k = $k, got " . InvestigateValue() . "\n"; sub InvestigateValue { return defined $k ? $k : 'undef'; }
wanted: $k = 1, got 1 wanted: $k = 2, got 2
Consider that my $k = 1; has two components, compile-time component my $k; and run-time component $k = 1;.wanted: $k = 1, got undef wanted: $k = 2, got 2
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Another variable scoping oddity
by Aristotle (Chancellor) on Nov 12, 2003 at 06:32 UTC | |
by Roger (Parson) on Nov 12, 2003 at 06:36 UTC | |
|
Re: Another variable scoping oddity
by pg (Canon) on Nov 12, 2003 at 06:24 UTC | |
by Roger (Parson) on Nov 12, 2003 at 06:32 UTC | |
|
Re: Another variable scoping oddity
by artist (Parson) on Nov 12, 2003 at 06:23 UTC | |
|
Re: Another variable scoping oddity
by davido (Cardinal) on Nov 12, 2003 at 06:32 UTC |