Possible Duplicates:
Perl sub to print out a variable and its value
How to get name of object in perl
I'm trying to create a sub called "debug" in an existing Perl script (which runs as a CGI under Apache2) and I want to call it from any other sub in the script and pass it the name of a local variable in that sub in order to inspect (and print out) the variable's current value.
For example:
sub somesub {
my $examplevar = 'abc';
debug('examplevar');
# or debug($examplevar); ??
}
The output in this case should be:
$examplevar: abc
I'm trying to avoid doing something like:
debug('examplevar', $examplevar);
because that's (and I'm hoping, unnecessary) extra typing.
The script has "use strict;" set and I've read "perldoc -q 'variable as a variable name'". Is there any way to achieve this without using symbolic references, while still only passing one parameter to the debug sub?