sharkey has asked for the wisdom of the Perl Monks concerning the following question:
But once, mysteriously, the debugger actually showed me the code which had been eval'd as I stepped through it. I figured if it can happen once, it can happen again, so I started investigating how it could happen.
perldebguts documents the @{"_<(eval 20)"} variables where the code for eval'd stuff should be stored. The trouble is, most of the time, there is no code there for my evals. I can look in the symbol table and see lots of other (eval ##) entries which do have code in them. For example, like this:
So my question for the perl debug gurus out there is, Why do some eval's get their code stored and others do not? Is there anything I can do to encourage my eval'd code to get stored?DB<20> p join "\n", map { "$_ $#{$_}" } grep /_<\(/, keys %::
EUREKA!
It is the presence of a named sub, or even a named sub stub, which convinces perl to keep the eval'd code in memory. So for my anonymous subs, I can do this:
The debugger can now show me the code for the anonymous sub, even if I use the same stub name in all of the evals.my $coderef = eval <<'EOF'; sub forget_me_not; sub { print "do some stuff"; } EOF
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: debugging eval'd code with source
by casiano (Pilgrim) on Jul 09, 2008 at 14:24 UTC | |
by sharkey (Scribe) on Jul 09, 2008 at 18:01 UTC |