ChrisBeall has asked for the wisdom of the Perl Monks concerning the following question:
Hi - I'm new to Perl.
In C, I had a nice simple macro to print a trace message with the script name, variable name, variable contents, and line number:
#define DEBUG(fmt,expr) \ fprintf(stderr, "DEBUG: " __FILE__ ":%d - " #expr " = [" #fmt "]\n", _ +_LINE__, expr);
Example: debug statement in my_script.c, line 32
10: char szMyString[] = "ContentsOfMyString"; 31: ... 32: DEBUG(%s, szMyString); 33: ... 34: ... ... output => DEBUG: my_script.c:32: - szMyString = [ContentsOfMyString]
What I really like about this is (a) it automatically prints the variable name "szMyString" (via the "#expr" value), and (b) the line number. But in Perl, I find myself always re-typing the variable name (Dumper tends to just print "$VAR1" etc):
print "\$mystring: [", $mystring, "]\n";Any suggestions on doing something similar in Perl, which automatically prints the variable name, would be greatly appreciated. Thanks a lot.
|
|---|