Is there a way to see or print a sub code?
Sometime a sub could be already defined, but in the debug mode (so, interactively) it could be already out of screen.
So, I would think about a way to check if the sub is defined (just 'defined' is not a problem) and how it is defined.
Also, if some modules were used, the same check would be useful
For example, is there a way to print out the pr()-code in followed:
~/develop/src> perl -de 0
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::(-e:1): 0
DB<1> sub pr { \
cont: print ">"; printf @_; print "\n<\n";\
cont: }
DB<3> pr "arg are: %s %d %f", "string", 123, 3.12
>arg are: string 123 3.120000
<
DB<4> pr yes if defined &pr
>yes
<
#!/usr/bin/perl
sub asdf($)
{
shift;
return 0;
}
if(defined("asdf"))
{
print "asdf is defined\n";
}
How about this:
$ perl -de 0
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::(-e:1): 0
DB<1> sub pr { \
cont: print ">"; printf @_; print "\n<\n";\
cont: }
DB<2>
DB<2> pr "arg are: %s %d %f", "string", 123, 3.12
>arg are: string 123 3.120000
<
DB<3> S pr
IO::Handle::print
IO::Handle::printf
IO::Handle::printflush
main::pr
DB<4> l
1==> 0
DB<4> l main::pr
Switching to file '(eval 13)[/usr/lib/perl5/5.8.8/perl5db.pl:628]'.
2 sub pr {
3: print ">"; printf @_; print "\n<\n";
4 };
DB<5>
1 Like
Perderabo:
Amaizing!
What the commands are the 'l' and 'S'?
The 'S' I guess, kind of 'search'?
OK, I have found: that is the debugger commands!
Anyway, BIG THANK YOU!
That exactly what I was looking for!
I have reviewed the debugger section in Larry Wall's Programming Perl book. He does come out and explicitly say why S and l are so named. Reading between the lines, I think that "S" might stand for "subroutines" and "l" seems to be chosen from "listing".