in reply to Problem generating a hashtable

the code below doesn't prove your statement. It works as expected on my system (perl 5.8, win xp). what's your perl?
use strict; my %hash = map { (split /:/, $_ )[0] => (split /:/, $_ )[2] } <DATA>; print join ",", sort keys %hash; #key1,key2 __DATA__ key1:useless:value1 key2:useless:value2

Update:
Darn, too slow again.


holli, /regexed monk/

Replies are listed 'Best First'.
Re^2: Problem generating a hashtable
by Tomtom (Scribe) on May 13, 2005 at 13:38 UTC
    The version of Perl I'm using is ... 5.005 :/
    I'd rather work on a 5.8, it you asked me, but I don't have the choice :(
      What's the output when you run my code above?


      holli, /regexed monk/
        With
        use strict; my %hash = map { (split /:/, $_ )[0] => (split /:/, $_ )[2] } <DATA>; print join ",", sort keys %hash; #key1,key2 __DATA__ key1:useless:value1 key2:useless:value2
        I get :
        key1,key2
        The thing is, I do the same thing as your code in mine, two times : the first time, with a first array given to the map function, it works fine ; but the second time, with another array, it "inverts" the keys and the values.