in reply to Re: Using the Variable Name from an Array
in thread Using the Variable Name from an Array

Simplified question what if I want to do this print the array element varibale name and value
Example:
$test=12; $test=13; @array=($test,$test2); foreach $value(@array) { print ?Variable_Name? $value; }

Getting @ the variable_name inside of the array is what I can not remember how to do.

Replies are listed 'Best First'.
Re^3: Using the Variable Name from an Array
by shmem (Chancellor) on Nov 14, 2019 at 17:13 UTC
    Getting @ the variable_name inside of the array is what I can not remember how to do.

    You don't have a variable_name inside of the array available by assignment. You have the values of the variables.

    If you want to access the values by name, do so using a hash:

    $test =12; $test2 =13; %hash=( test => $test, test2 => $test2, ); foreach $name(qw(test test2)) { print "$name $hash{$name}\n"; }
    perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'
Re^3: Using the Variable Name from an Array
by choroba (Cardinal) on Nov 14, 2019 at 17:11 UTC
    The array stores the values, not the variables and their names.
    map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]