SS Hegde
SS Hegde

Reputation: 739

Modifying the variable's value during debugging perl code

I was debugging a perl program on SuSe Linux using "perl -d" switch.

While debugging, the program was reporting XYZ variable is not set

How can I set the value of XYZ inside the debugger?

I tried following inside the debugger but not working.

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

I did a bit of google on this. But couldn't find what I wanted.

Upvotes: 4

Views: 2899

Answers (2)

matt freake
matt freake

Reputation: 5090

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

$XYZ = 'ABC'

If you use

my $XYZ='ABC'

it will define the variable $XYZ in the current scope only. From testing in the debugger it looks like that scope does not extend outside the debug console (i.e it is only accessible on that line of the console). E.G.

  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.

Upvotes: 1

simbabque
simbabque

Reputation: 54323

The debug console takes Perl expressions, so you need to quote the value if it is a string.

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

> $XYZ='ABC'

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

Upvotes: 3

Related Questions