in reply to Re: Scope of lexical variables in the main script
in thread Scope of lexical variables in the main script
Thanks, got it :-)
One more question about lexical variables. If I define a lexical variable in a block, what happens to the memory storing the value of the lexical variable after the code exits the block?
For example, in the script below. I cannot directly access $tricky outside the block. But it can be done with a reference. My question is if the memory storing the contents of $tricky has been released right after the block ends? If so, does it mean some other programs can write to that memory and when I try to retrieve the value of $tricky with a reference after the block, I may get something unexpected(memory got overwritten by other program)?
#!/usr/bin/pere my $reference; { my $tricky = "TRICKY"; $reference = \$tricky; } print "\$tricky is not defined\n" unless $tricky ; # What happens to the memory storing the contents of $tricky? # Has the memory storing $tricky been released? print "Using a reference, here you are: $$reference\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Scope of lexical variables in the main script
by davido (Cardinal) on Apr 20, 2012 at 05:58 UTC | |
|
Re^3: Scope of lexical variables in the main script
by Marshall (Canon) on Apr 20, 2012 at 06:33 UTC | |
by sophate (Beadle) on Apr 20, 2012 at 06:53 UTC | |
|
Re^3: Scope of lexical variables in the main script
by Anonymous Monk on Apr 20, 2012 at 06:07 UTC | |
|
Re^3: Scope of lexical variables in the main script
by nemesdani (Friar) on Apr 20, 2012 at 06:58 UTC |