Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re: Get same position value in 2nd array

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

in reply to Get same position value in 2nd array

I have decided to attempt this with hashes, however am now confused as to why my loop doesn't evaluate the table in order. For example, this code:

use strict; my %table = qw/test0 0 test1 1 test2 2 test3 3 test4 4 test5 5 test6 6 + test7 7/; while ( my($key, $value) = each(%table) ) { if ($value ne '0') { print "$key = $value\n" } }

...produces the following result:

test5 = 5

test7 = 7

test1 = 1

test4 = 4

test6 = 6

test3 = 3

test2 = 2

Replies are listed 'Best First'.
Re^2: Get same position value in 2nd array
by BrowserUk (Pope) on Dec 22, 2012 at 01:30 UTC
    I have decided to attempt this with hashes

    You know you want ordered results, but decide to use an inherently unordered data structure; that's like wanting to travel to Vegas and buying a boat.

    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

    RIP Neil Armstrong

Re^2: Get same position value in 2nd array
by Anonymous Monk on Dec 21, 2012 at 04:05 UTC
    Sure its evaluated in order :) it is not the order you want, but thats just how hashes work

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (8)
As of 2017-12-15 13:42 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (432 votes). Check out past polls.