in reply to Using the Variable Name from an Array

It's not 100% clear to me what you want to do or expect to happen here, but perhaps an AoH would be better suited than a plain array?

#!/usr/bin/env perl use strict; use warnings; my $id = 'foo'; my $Record_Lock = 'bar'; my $Record_Change_Date = 'baz'; my @elements = ( {name => 'id', value => $id }, {name => 'Record_Lock', value => $Record_Lock }, {name => 'Record_Change_Date', value => $Record_Change_Date} ); for my $elem (@elements) { print "Elem name $elem->{name} has value $elem->{value}\n"; }

Replies are listed 'Best First'.
Re^2: Using the Variable Name from an Array
by perlgates (Initiate) on Nov 14, 2019 at 16:58 UTC
    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.
      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'
      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]