in reply to Nervously....How do I access the Name of a Perl variable?

It's possible to write something tremendously clever that does it all in a subroutine, but if you're debugging like that, just create a line like
print __FILE__ . " (" . __LINE__ . "): " . "(your variable names and values here)\n";
and copy it willy nilly, wherever needed. When you're tired of it, just comment it out .. you may end up needing it again.

This presumes that you can't use the Perl debugger to track down your problem. The debugger is a little intimidating, but it's a little cleaner and neater (not to mention way more flexible) to use when tracking down problems.

--t. alex

"Nyahhh (munch, munch) What's up, Doc?" --Bugs Bunny

Update Abigail's suggestion is much cooler -- it gets Perl to take care of the file name and line numbering detail.

It's really a preference between commenting out code that's no longer needed and just disabling it with the $debug flag. Your choice.

Replies are listed 'Best First'.
Re: Nervously....How do I access the Name of a Perl variable?
by Abigail-II (Bishop) on Jun 11, 2002 at 09:43 UTC
    Or you would just use:
    warn "Your variable names and values here" if $debug;
    and Perl will supply the file name and line number for you.

    By toggling the $debug variable, you can control whether the program prints debugging messages or not.

    Abigail