Get variable name as string in Perl

后端 未结 3 1082
一个人的身影
一个人的身影 2021-01-04 10:31

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 = &         


        
3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-04 11:26

    Data::Dumper::Simple

    use warnings;
    use strict;
    use Data::Dumper::Simple;
    
    my $abc = '123';
    my ($var_name) = split /=/, Dumper($abc);
    print $var_name, "\n";
    
    __END__
    
    $abc
    

提交回复
热议问题