Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

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.


Comment on Re: Get same position value in 2nd array
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1009939]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2014-07-26 16:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (178 votes), past polls