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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.