in reply to Split results of Map function
Based on what you describe as the desired output, it looks like you want to keep just the first value assoicated with a given key, and ignore later values. (But you didn't actually say this, so I'm just guessing.) If that is the case, you would want to alter the code in one of the earlier replies so that you check for the existence of a hash key before you assign a value to it. Using thesa's solution, for instance:
This will make sure that once a value is assigned to a given hash key, no other value will be assigned to that key (assuming this is what you want).my %hash = (); while(<DATA>) { chomp; my ($k, $v) = split / \s+ \d+ , \s+ /x; $hash{$k} = $v unless exists $hash{$k}; }
|
|---|