Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^2: Debugger and lexicals

by Anonymous Monk
on Aug 07, 2011 at 10:16 UTC ( [id://919051]=note: print w/replies, xml ) Need Help??


in reply to Re: Debugger and lexicals
in thread Debugger and lexicals

No; there is no control or sandbox and the debugger, being written in perl, is part of perl.

Lexical variables are only accessible from within a lexical scope, because they only exist within a lexical scope.

You can use padwalker (y) to list lexicals in a higher scope.

I think jethro is right, and my $a probably gets optimized away

Replies are listed 'Best First'.
Re^3: Debugger and lexicals
by Khen1950fx (Canon) on Aug 07, 2011 at 11:09 UTC
    Some of what you say I can agree with. But "they only exist within a lexical scope"---and why's that? It's because lexical variables cannot access the symbol table. That's why I mentioned that there's a control "sandboxed" way from the debugger. Package variables can be accessed via the symbol table.

    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:

    #!/usr/bin/perl use strict; use warnings; print mt2(55), "\n"; my $a = 23; sub mt2 { my $b = $_[0] * 2; return $a + $b; }
    Here's the corrected script:
    #!/usr/bin/perl use strict; use warnings; print mt2(55), "\n"; sub mt2 { my $a = 23; my $b = $_[0] * 2; return $a + $b; }
    This one works in the debugger. Thanks for the input.

      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 :)

      $a is defined
      The "problem" of $a being undefined, is because it is optimized away -- really because the sub which we're stepping into (ASDF) doesn't refer to it

      Here, a different sub refers to $a, so when we step into ASDF, $a is still undefined -- it is not attached to ASDF's Scratchpad

      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

        Stricly speaking $a is not optimised away; it just has a short life span, as as I pointed out earlier.
        $ cat /tmp/Foo.pm package Foo; sub DESTROY { print "DESTROY\n" } my $a = bless {}; print "executing Foo\n"; $ perl -I/tmp -e'use Foo; BEGIN { print "BEGIN\n" }' executing Foo DESTROY BEGIN

        Dave.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://919051]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (3)
As of 2024-04-24 01:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found