Thanks for your answer. Here's a more concrete example to show the problem.
$ cat -n tt 1 #!/usr/bin/perl 2 3 my $perl = <<'EOF'; 4 sub { 5 my $x = 123; 6 $x += shift; 7 print "x is $x\n" 8 } 9 EOF 10 11 my $cf = eval $perl; 12 13 $cf->(4); $ perl -d tt Loading DB routines from perl5db.pl version 1.28 Editor support available. Enter h or `h h' for help, or `man perldebug' for more help. main::(tt:3): my $perl = <<'EOF'; main::(tt:4): sub { main::(tt:5): my $x = 123; main::(tt:6): $x += shift; main::(tt:7): print "x is $x\n" DB<8> s main::(tt:11): my $cf = eval $perl; DB<8> s main::((eval 20)[tt:11]:7): ;
Now we are inside the eval, and we can see the code...
DB<8> p $#{"_<(eval 20)[tt:11]"} 7 DB<9> l (eval 20) 1 sub { 2: my $x = 123; 3: $x += shift; 4: print "x is $x\n" 5 } 6 7==> ;
But as soon as we step out of the eval, the code is gone...
DB<10> s main::(tt:13): $cf->(4); DB<10> p $#{"_<(eval 20)[tt:11]"} -1
And yet, there are other evals out there, for the code stays around...
DB<11> p join "\n", map { "$_ $#{$_}" } grep /_<\(/, keys %:: _<(eval 20)[tt:11] -1 _<(eval 22)[/usr/lib/perl5/5.8.8/SelfLoader.pm:38] 6 _<(eval 11)[/usr/lib/perl5/5.8.8/SelfLoader.pm:111] 1 _<(eval 12)[/usr/lib/perl5/5.8.8/SelfLoader.pm:38] 40 _<(eval 5)[/usr/lib/perl5/5.8.8/Term/ReadLine.pm:306] -1 _<(eval 21)[/usr/lib/perl5/5.8.8/SelfLoader.pm:38] 10 _<(eval 23)[/usr/lib/perl5/5.8.8/SelfLoader.pm:38] 20 _<(eval 26)[/usr/lib/perl5/5.8.8/perl5db.pl:628] 4 DB<13> f eval 22 Choosing (eval 22)[/usr/lib/perl5/5.8.8/SelfLoader.pm:38] matching `ev +al 22': 1 package readline; sub F_PreviousHistory { 2: &get_line_from_history($rl_HistoryIndex - shift); 3 } 4 5 6 ;
I no longer can get to my eval'd code...
DB<14> f eval 20 Choosing (eval 20)[tt:11] matching `eval 20': DB<15> l
And neither can the debugger...
DB<15> s main::CODE(0x97b7d28)((eval 20)[tt:11]:2): 2: DB<15> main::CODE(0x97b7d28)((eval 20)[tt:11]:3): 3: DB<15> main::CODE(0x97b7d28)((eval 20)[tt:11]:4): 4: DB<15> x is 127 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.
So the question remains, why does my eval'd source code get discarded, while other eval'd source code stays in memory? And what can I do to convince perl to keep my eval'd source code?

In reply to Re^2: debugging eval'd code with source by sharkey
in thread debugging eval'd code with source (SOLVED) by sharkey

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.