Solved

How to debug into sub functions in Perl?

Posted on 2011-03-24
3
486 Views
Last Modified: 2012-05-11
Hi,
I have subfunction in my code and Perl debugger cannot go into it.

Here is what I do:

perl -d myFile
b linenumber
c
s

Open in new window



It stops at linenumber and when I say step into it it skips. n also does not work.

Here is the beginning of my sub function:

SOME CODE

my (%c, %d);
sub logFunc {
    my ($a, $b) = @_;
    my $S;
    my $file;

SOME OTHER CODE

} #myFunc

SOME MORE CODE

Open in new window



How can I debug this code?
0
Comment
Question by:Tolgar
3 Comments
 
LVL 8

Expert Comment

by:point_pleasant
ID: 35210385
n runs until the next statement (the one immediately following this one in the current file) is about to execute. Note that if the current line is a subroutine call, the debugger won't stop until returning from that subroutine. To stop at the first line of the called subroutine, use the s (single-step) command instead. The r command executes until returning from the current subroutine (i.e., until we pop the activation stack).

0
 

Author Comment

by:Tolgar
ID: 35210568
Well, I already use s but it still does not go into the subroutine. Why is that?

Thanks,
0
 
LVL 25

Accepted Solution

by:
clockwatcher earned 500 total points
ID: 35211636
This may be a stupid question but are you expecting what you posted to actually step into that function?  

SOME CODE

my (%c, %d);
sub logFunc {
    my ($a, $b) = @_;
    my $S;
    my $file;

SOME OTHER CODE

} #myFunc

Open in new window


If you are, that's your problem right there.  The code that you posted never calls your function so the debugger won't ever actually be in there to step into it.  If you actually call your function, then you'll step into that section of the code.

SOME CODE

my (%c, %d);
sub logFunc {
    my ($a, $b) = @_;
    my $S;
    my $file;

SOME OTHER CODE

} #myFunc

# call your function
my $val = logFunc( 5, 5);

Open in new window

0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Perl for loop for 2000 ms 7 100
Perl, group, sort, count question 6 136
File Find regex problem 4 62
Regex rule to match two different url 5 74
Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question