Changing the value of a variable while debugging perl code

I debugged a Perl program on SuSe Linux using the perl -d switch.

During debugging, the program reported XYZ variable is not set

How to set the XYZ value inside the debugger?

I tried following inside the debugger but did not work.

 set XYZ=ABC my $XYZ=ABC setenv XYZ ABC 

I did a little google on this. But I could not find what I wanted.

+4
source share
2 answers

The debug console accepts Perl expressions, so you need to specify a value if it is a string.

You will need to move the program to the line that throws the error (look at the breakpoints, b <line> in the debugger), and then set the value.

 > $XYZ='ABC' 

Here's a good resource: http://obsidianrook.com/devnotes/talks/perl_debugger/

+4
source

Assuming you are trying to set $ XYZ to an ABC try string:

 $XYZ = 'ABC' 

If you use

 my $XYZ='ABC' 

it will only define the $ XYZ variable in the current scope. From testing in the debugger, it looks like this area does not extend outside the debugging console (i.e., it is available only in this console line). For instance.

  DB<2> my $x = "hello"; print "$x" hello DB<3> print $x Use of uninitialized value $x in print at (eval 8)[/usr/share/perl/5.12/perl5db.pl:638] line 2. 
+2
source

Source: https://habr.com/ru/post/1444295/


All Articles