Get variable name as string in Perl

Posted by Jose Cuervo on Stack Overflow See other posts from Stack Overflow or by Jose Cuervo
Published on 2011-03-04T22:11:00Z Indexed on 2011/03/04 23:25 UTC
Read the original article Hit count: 218

Filed under:
|

Hi, I am trying to get a text representation of a variable's name. For instance, this would be the function I am looking for:

$abc = '123';
$var_name = &get_var_name($abc); #returns '$abc'

I want this because I am trying to write a debug function that recursively outputs the contents of a passed variable, I want it to output the variable's name before hand so if I call this debug function 100 times in succession there will be no confusion as to which variable I am looking at in the output.

I have heard of Data::Dumper and am not a fan. If someone can tell me how to if it's possible get a string of a variable's name, that would be great.

Thanks!

© Stack Overflow or respective owner

Related posts about perl

Related posts about variables