On Feb 1, 2008 8:04 AM, Cort Morgan <[EMAIL PROTECTED]> wrote:
> Can anyone tell me is it possible to look at the current value
> of a variable in a package method, if the package was included
> in the main program with a use statement?
Yes and kinda. If it's a package variable, yes; if it's a lexical
variable, you can see it from within its scope. But it doesn't depend
upon the 'use' statement. Here's a good explanation of the basics:
http://perl.plover.com/FAQs/Namespaces.html
If you know a variable's full name, including its package name, you
can access it from any line of code.
my $old_voltage = $Electro::Shock::electrode_volts;
my $new_voltage = ($old_voltage + 20) * 150; # evil laugh
$Electro::Shock::electrode_volts = $new_voltage;
If it's a lexical ("my") variable, it doesn't have a package name. Its
name is valid only within its scope. But if you stop the debugger
within its scope, that qualifies.
> I've tried
> V ABC::def varname
That looks as if you're trying to examine $ABC::def::varname, or the
same name with a different sigil in front. That's a package variable,
not a lexical. Is that right? I would usually name the variable
directly in an x command; the debugger's x command shows you the
result of any expression.
This command examines the variable %optionVars in the DB package,
which is used by the debugger. The leading pipe character causes the
debugger to pipe the output to a pager program for easy reading; the
backslash preserves the structure of the hash:
|x \%DB::optionVars
If you're trying to access a lexical variable, though, you'll need to
stop the debugger somewhere within the scope of that lexical in order
to access it by name. That's easy to do with a breakpoint.
Hope this helps!
--Tom Phoenix
Stonehenge Perl Training
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/