in reply to Loading a hash table
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.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,,,
|
|---|