in reply to Displaying a variable's name and value in a sub
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.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'
There is not a way to easily get the calling variable name from the sub that called this sub even with C macro expansion.
|
|---|