perl: a way to see a sub code in debug mode: perl -de 0 ?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting perl: a way to see a sub code in debug mode: perl -de 0 ?
# 1  
Old 01-20-2011
perl: a way to see a sub code in debug mode: perl -de 0 ?

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:
Code:
~/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
<

# 2  
Old 01-20-2011
Code:
#!/usr/bin/perl

sub asdf($)
{
        shift;
        return 0;
}

if(defined("asdf"))
{
        print "asdf is defined\n";
}

# 3  
Old 01-20-2011
How about this:
Code:
$ 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>

This User Gave Thanks to Perderabo For This Post:
# 4  
Old 01-20-2011
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!
# 5  
Old 01-21-2011
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".
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

PERL: In a perl-scripttTrying to execute another perl-script that SETS SOME VARIABLES !

I have reviewed many examples on-line about running another process (either PERL or shell command or a program), but do not find any usefull for my needs way. (Reviewed and not useful the system(), 'back ticks', exec() and open()) I would like to run another PERL-script from first one, not... (1 Reply)
Discussion started by: alex_5161
1 Replies

2. Shell Programming and Scripting

Perl Debug Stepping Answering Questions

I am new to perl and want to get a little better understanding of debugging code in perl. I have a perl script that has questions to be answered like: he following PERL modules are recommended: Crypt::DES Crypt::PasswdMD5 IO::Pty Net::Write::Layer2 String::CRC32 Attempt to install... (0 Replies)
Discussion started by: metallica1973
0 Replies

3. Shell Programming and Scripting

Debug perl script

Hi, I am trying to get squid up and running using a redirector process, and every time I try to load a web page, squid fails miserably. Can some one with perl and squid knowledge take a look at these codes and tell if something is wrong here. #!/usr/bin/perl # $| = 1; @endings = qw/... (0 Replies)
Discussion started by: jamie_123
0 Replies

4. Shell Programming and Scripting

Logging perl and shell debug mode.

I have a shell program which calls a perl program. I am running the shell program with command; $ ksh -x <prog_name> Inside the shell program, I am calling perl with warnings. I want to capture the entire output as it comes on screen. The command I tried is: $ ksh -x... (1 Reply)
Discussion started by: som.nitk
1 Replies

5. Programming

Perl- How to catch the file in perl code?

Hi, plz see the below code , i have catch the file "Orders.20110714.out "file as a Orders*.out. but it giving me an error .it does not open the file. if the same thing i have done by code code-> ls Orders*.out then it gives me the output Orders.20110714.out i am trying apply the... (1 Reply)
Discussion started by: pspriyanka
1 Replies

6. Shell Programming and Scripting

Debug mode

When I run a lengthy script in debug mode i need to capture all the steps which are executed. e.g ksh -x script.ksh + test -f /proc/mounts + /bin/ls -l /proc/21326/exe + is=ksh + test ksh = ksh + test -s /etc/ksh.kshrc + . /etc/ksh.kshrc + trap 1 2 3 + who am i + awk {print $1} +... (2 Replies)
Discussion started by: zooby
2 Replies

7. Shell Programming and Scripting

PERL: NET::FTP..>Debug Messages

HI All, NET::FTP->new($server, DEBUG=>1); I need to get all the Debug Messages in an array or a file.... Please suggest!! (0 Replies)
Discussion started by: angad.makkar
0 Replies

8. Shell Programming and Scripting

Perl Interactive mode

Hi All, Does perl has an interactive mode like other shell? If there is, can any one show me the equivalent code for the below csh script ? This csh code prompts user for their name and prints the name. #!/bin/csh echo -n "Pls enter the your name: " set name = ($<) echo "You hav... (2 Replies)
Discussion started by: Raynon
2 Replies

9. Shell Programming and Scripting

strange net::SFTP Perl module debug entry

I installed Net::sftp on a solaris 8 server and I am able to successfully transfer files to the remote server. I am running the command out of a script with debug=1 on so I can see the verbose output. The last two lines of the debug output show it couldn't fsetstat, but I don't know what that... (2 Replies)
Discussion started by: csgonan
2 Replies

10. Shell Programming and Scripting

what's the debug command for perl scripts

Hi, Can you please let me know if there's any debug command for perl scripts like set -x for shell scripts (2 Replies)
Discussion started by: dayanandra
2 Replies
Login or Register to Ask a Question