in reply to Re^3: Debugger and lexicals
in thread Debugger and lexicals
and why's that? It's because lexical variables cannot access the symbol table.
No, its because they're initialized at runtime and stored in a pad/Scratchpads, which are attached to subroutines ... http://search.cpan.org/dist/illguts/
As for my $a getting optimized away, I disagree with that because I just don't see how it can be optimized away when it's uninitialized in the subroutine. Here's a little test that I ran:
Your example is different.
In your example, $a is initialized after the call to mt2.
And you never remove a reference to $a, so it never gets optimized away.
Here is what you intended :)
#!/usr/bin/perl -- use strict; use warnings; print ASDF(19), "\n"; BEGIN { my $a = 22; sub ASDF { my $b = $_[0] + 1; $a + $b; } }
perl.exe -d pm.919064.1.pl Default die handler restored. Loading DB routines from perl5db.pl version 1.07 Editor support available. Enter h or `h h' for help, or `man perldebug' for more help. main::(pm.919064.1.pl:4): print ASDF(19), "\n"; main::(pm.919064.1.pl:5): BEGIN { DB<1> s main::ASDF(pm.919064.1.pl:8): my $b = $_[0] + 1; DB<1> x $a 0 22 DB<2> s main::ASDF(pm.919064.1.pl:9): $a + $b; DB<2> s 42 Debugged program terminated. Use q to quit or R to restart, use O inhibit_exit to avoid stopping after program termination, h q, h R or h O to get additional info. DB<2> q
#!/usr/bin/perl -- use strict; use warnings; print ASDF(19), "\n"; BEGIN { my $a = 22; sub ASDF { my $b = $_[0] + 1; } }
perl.exe -d pm.919064.2.pl Default die handler restored. Loading DB routines from perl5db.pl version 1.07 Editor support available. Enter h or `h h' for help, or `man perldebug' for more help. main::(pm.919064.2.pl:4): print ASDF(19), "\n"; main::(pm.919064.2.pl:5): BEGIN { DB<1> s main::ASDF(pm.919064.2.pl:8): my $b = $_[0] + 1; DB<1> x $a 0 undef DB<2> s 20 Debugged program terminated. Use q to quit or R to restart, use O inhibit_exit to avoid stopping after program termination, h q, h R or h O to get additional info. DB<2> q
#!/usr/bin/perl -- use strict; use warnings; print ASDF(19), "\n"; BEGIN { my $a = 22; $a += 0; sub ASDF { my $b = $_[0] + 1; } sub DADA { $a } }
perl.exe -d pm.919064.4.pl Default die handler restored. Loading DB routines from perl5db.pl version 1.07 Editor support available. Enter h or `h h' for help, or `man perldebug' for more help. main::(pm.919064.4.pl:4): print ASDF(19), "\n"; main::(pm.919064.4.pl:5): BEGIN { DB<1> s main::ASDF(pm.919064.4.pl:9): my $b = $_[0] + 1; DB<1> x $a 0 undef DB<2> s 20 Debugged program terminated. Use q to quit or R to restart, use O inhibit_exit to avoid stopping after program termination, h q, h R or h O to get additional info. DB<2> q
You should consider not answering or prefacing your guesses (see To Answer, Or Not To Answer....), because there won't always be someone there to answer when Duty Calls
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Debugger and lexicals
by dave_the_m (Monsignor) on Aug 07, 2011 at 12:57 UTC | |
by Anonymous Monk on Aug 07, 2011 at 13:37 UTC | |
by dave_the_m (Monsignor) on Aug 07, 2011 at 15:35 UTC |