good chemistry is complicated, and a little bit messy -LW |
|
PerlMonks |
Re: Displaying a variable's name and value in a subby Marshall (Canon) |
on Feb 15, 2011 at 09:42 UTC ( [id://888175]=note: print w/replies, xml ) | Need Help?? |
I find the idea, "This is trivial in C/C++ using macros" hard to believe. I can't see any trivial way without expanding the number of args to showx(). Of course you can use the C pre-possessor to do macro expansion and send that result into Perl if you wanted to do so. The C pre-processor does not know any thing about the C language. I would be curious as what you come up with. But I doubt that your original claim is correct. Perl has position dependent variable passing, just like 'C'. "show1()" should be saying something like "name was $name" where "$name = shift;". For show1() to display a calling variable name, it would have to have an additional parameter, $souce_code_name. There is not a way to easily get the calling variable name from the sub that called this sub even with C macro expansion.
In Section
Seekers of Perl Wisdom
|
|