I'm seeking enlightenment! This is about the Perl debugger and lexicals ('my' variables). Here's a script:

#! /usr/bin/perl -ws use mytest2; print mt2(55), "\n";

And here's the module it use's:

#! /usr/bin/perl -w package mytest2; require Exporter; our @ISA = qw( Exporter ); our @EXPORT = qw( mt2 ); my $a = 23; sub mt2 { my $b = $_[0] * 2; # return $a + $b; } 1;

My problem is this: With the return line in mt2() commented as shown, I run the top script via 'perl -d' and single-step to the first line of mt2() (that line hasn't executed yet). The debug command 'x $a' returns 'undef' - the debugger can't 'see' $a, even though it is declared earlier in the module file.

When the indicated line is uncommented, this isn't the case anymore -- the debugger reports the proper value of $a before the first line of mt2() is executed, even before it gets referenced or used (in the second line).

I can add code to reference the lexical vars in a module's subroutine that I can set a breakpoint in. But can I not access those lexicals directly? - anyway? - via the debugger?


In reply to Debugger and lexicals by lzipin

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.