in reply to Displaying a variable's name and value in a sub

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.

sub show1 { ... } sub show2 { ... } my $a = 'foo'; show1($a); #desired print $a='foo' show2('$a'); #desired print $a='foo' $a = 'foobar'; show1($a); #desired print $a='foobar'
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.