I have the following text file of configuration details. This is a inhertitance configured file
.######## PARENT CONFIG ############## DEPLOY : SWG_Lower HOLDS SWG_Depot EQUALS:= total_dist: completion= SUCCESS total_finish: completion= SUCESS total_cancel:completion=SUCCESS DEPLOYED DEPLOY: LOADED_Lower HOLDS SWG_Depot EQUALS = total_finish: completion= SUCCES total_cancel: completion=SUCCESS DEPLOYED DEPLOY: CONFIG_Lower HOLDS SWG_Depot EQUALS = total_cancel: completion=SUCCESS DEPLOYED ######### INHERITED CHILD CONFIG ############### DEPLOY first_distribution HOLDS LOADED_Lower DEPLOYED DEPLOY: second_distribution HOLDS CONFIG_Lower ; DEPLOYED DEPLOY : third_distribution HOLDS LOADED_Lower; DEPLOYED DEPLOY : forth_distribution HOLDS SWG_Lower ; DEPLOYED
I need to match a string variable with a hash key. The fields first_distribution , second_distribution are keys stored in a hash called results{keyid} and I match them in this file. What I am doing is follows. I first match a key in the file, then I need to collate the attributes associated with each PARENT ID, attributes for example are total_dist:, total_cancel
while( $line = <FH>) { next unless $line =~ m<\s+(\S+)\sHOLDS\s(.+)>x; $key = $1; #Obtains first_distribution, etc if ($line =~ /(\S+_Lower)\sHOLDS\s\S+/i) { $base_type = $1; #obtains parent config ID (eg SWG_Lo +wer ) while ($line =~ m<\s(\S+):\s(completion).+>gx) # obta +ining attributes { push(@{$base{$base_type}}, $1);}} # push each att +ribute associated with parent ID into an hash of arrays # eg A dump from the hash looks like this whi +ch is correct SWG_Lower:: total_dist total_finish total_cancel LOADE +D_Lower:: total_finish, total_cancel : CONFIG +_Lower: total_cancel next unless exists $results{$key}; # I do this incase ther +e are distribution ids in the file which are not in my hash
Now where Im struggling is as follows.. The child IDs need to inherit the PARENT attributes if distributions holds one of the PARENT IDS, example
eg. The child ID second_distribution HOLDS CONFIG_Lower which matches CONFIG_Lower in the base{$base_type) hash key therefore needs to inherit the attribute from CONFIG_lower and push into an already pre-defined hash of hashes value $results{Łkey}{$dist_attr}
DEPLOY: second_distribution HOLDS CONFIG_Lower ; DEPLOYED
Therefore the attribute " total_cancel" needs to associated with second_distribution, and if it is, update an hash key called $results{Łkey}{$dist_attr} with the value total_cancel, an example for forth_distribution would be
DEPLOY : forth_distribution HOLDS SWG_Lower ; DEPLOYED
The attributes total_dist, total_cancel and total_finish (attributes of SWG_Lower) would need to be joined with # and the following value total_dist#total_cancel#total_finish pushed into $results{Łkey}{$dist_attr} hash value. Does this make sense? it was hard for me to explain never mind write
In reply to Matching String Value with Hash Key by Mark.Allan
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |