Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Loading a hash table

by TedPride (Priest)
on Jan 03, 2006 at 20:19 UTC ( [id://520717]=note: print w/replies, xml ) Need Help??


in reply to Loading a hash table

Assuming the format is the way you say it is, the following should work fine:
use strict; use warnings; my @keys = ( 'Name', 'AlarmConsistencyMgr', 'AlarmForwarder', 'AlarmForwarderServer', 'alert_publisher', 'AnalogGatewayMain', 'AssetTracking', 'CallerPosition', ); $_ = <DATA>; chomp; my @vals = split /,/; my %hash; @hash{@keys} = @vals; for (@keys) { print "$_ -> $hash{$_}\n"; } __DATA__ ,,,X,X,,X,X,X,X,X,X,X,,,,,,,X,X,X,,,,X,,,,,,,,X,,,,,X,,,
Your problem was that hash keys are not stored in the order they're specified, so your initialization order had nothing to do with the order in which the values were assigned. You have to use an array to preserve order.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2024-04-25 19:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found