Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re: Get same position value in 2nd array

by Phinix (Acolyte)
on Dec 21, 2012 at 17:02 UTC ( #1009939=note: print w/replies, xml ) Need Help??

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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1009939]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (8)
As of 2018-06-20 16:11 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (116 votes). Check out past polls.