http://www.perlmonks.org?node_id=1009939


in reply to Get same position value in 2nd array

Perhaps I can clarify a bit. Consider the following code:

use strict; my @numbers = qw/1 2 3 4 5/; my %wht = qw/number1 $numbers[0] number2 $numbers[1] number3 $numbers[ +2] number4 $numbers[3] number5 $numbers[4]/; while ( my($key, $value) = each(%wht) ) { if ($value ne '0') { print "$key = $value\n" } }

My goal is to have the if statement print the string contained in the key position followed by the actual value (numerical in this example) of the array value in the values position. So, for the first table entry, it should print "number 1 = 1". However, what the above produces is instead "number1 = $numbers[0]", etc.

So, how can I do this sort of lookup on a hash key and work with the actual value of the variable in the value position, not just it's string identifier?

This is not "homework." I am simply unfamiliar with the syntax, and documentation on this sort of operation is extremely sparse.