if ($_ eq $key){
...
####
use Data::Dumper;
use strict;
# Define actual names (values) for the references (keys) in a hash table
my %mapped_vars = ( '1a' => 'One' '2a' => 'Two',
'3a' => 'Three',
'4a' => 'Four' );
# List of array variables that has to be evaluated. It can also have names that are NOT present in the hash table
my @arr_vars = ( '3a','9d', '4a', '7b');
my (@act_vars, $i);
my $found=0;
# Checking...
print Dumper(\%mapped_vars);
print Dumper(\@arr_vars);
foreach (@arr_vars){
while( (my $key, my $value) = each %mapped_vars){
print "$_-inside while()";
if ($_ eq $key){
push @act_vars, $value;
$found =1;
#last;
}
#last LBL;
}
unless ($found){
print "Inside unless()\n";
push @act_vars, $_;
}
$found = 0;
print "\n";
}
print Dumper(\@act_vars);
####
$VAR1 = {
'3a' => 'Three',
'2a' => 'Two',
'4a' => 'Four',
'1a' => 'One'
};
$VAR1 = [
'3a',
'9d',
'4a',
'7b'
];
---------------------------------------
3a-inside while()3a-inside while()3a-inside while()3a-inside while()
9d-inside while()9d-inside while()9d-inside while()9d-inside while()Inside unless()
4a-inside while()4a-inside while()4a-inside while()4a-inside while()
7b-inside while()7b-inside while()7b-inside while()7b-inside while()Inside unless()
------------------------
$VAR1 = [
'Three',
'9d',
'Four',
'7b'
];