Okay, so as you indicate, this is complicated and difficult to explain -- worse to have to type it out. I empathize -- truly.

So naturally the first thing I need to do is get into your headspace -- easiest way is to take your data and code and run it to get a feel for what it is trying to do.

So I wrapped your code in a subroutine (mainly to isolate my code from yours) and called it.

Either you didn't give me everything, or something is seriously wrong with your code:

#!/usr/bin/perl -w use strict; foreach my $configFilename (@ARGV) { if (open FH, '<', $configFilename) { &processConfigFile(); } } exit; __END__ C:\Steve\Dev\PerlMonks\P-2013-09-27@1720-Config-Parent>perl configPare +nt.pl Bareword "LOADED_Lower::" refers to nonexistent package at configParen +t.pl line 32. Global symbol "$line" requires explicit package name at configParent.p +l line 19. Global symbol "$line" requires explicit package name at configParent.p +l line 21. Global symbol "$key" requires explicit package name at configParent.pl + line 22. Global symbol "$line" requires explicit package name at configParent.p +l line 24. Global symbol "$base_type" requires explicit package name at configPar +ent.pl line 26. Global symbol "$line" requires explicit package name at configParent.p +l line 28. Global symbol "%base" requires explicit package name at configParent.p +l line 30. Global symbol "$base_type" requires explicit package name at configPar +ent.pl line 30. syntax error at configParent.pl line 32, near "LOADED_Lower:: total_fi +nish" Global symbol "%results" requires explicit package name at configParen +t.pl line 35. Global symbol "$key" requires explicit package name at configParent.pl + line 35. Missing right curly or square bracket at configParent.pl line 39, at e +nd of line configParent.pl has too many errors.

So we'll need to get past this before I'm going to be of much use to you.

The full code I used is here so we can compare apples to apples as we work through this:

#!/usr/bin/perl -w use strict; foreach my $configFilename (@ARGV) { if (open FH, '<', $configFilename) { &processConfigFile(); } } exit; sub processConfigFile { 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 } __END__ C:\Steve\Dev\PerlMonks\P-2013-09-27@1720-Config-Parent>perl configPare +nt.pl Bareword "LOADED_Lower::" refers to nonexistent package at configParen +t.pl line 32. Global symbol "$line" requires explicit package name at configParent.p +l line 19. Global symbol "$line" requires explicit package name at configParent.p +l line 21. Global symbol "$key" requires explicit package name at configParent.pl + line 22. Global symbol "$line" requires explicit package name at configParent.p +l line 24. Global symbol "$base_type" requires explicit package name at configPar +ent.pl line 26. Global symbol "$line" requires explicit package name at configParent.p +l line 28. Global symbol "%base" requires explicit package name at configParent.p +l line 30. Global symbol "$base_type" requires explicit package name at configPar +ent.pl line 30. syntax error at configParent.pl line 32, near "LOADED_Lower:: total_fi +nish" Global symbol "%results" requires explicit package name at configParen +t.pl line 35. Global symbol "$key" requires explicit package name at configParent.pl + line 35. Missing right curly or square bracket at configParent.pl line 39, at e +nd of line configParent.pl has too many errors.

In reply to Re: Matching String Value with Hash Key by marinersk
in thread 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.