in reply to Matching String Value with Hash Key
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.
|
|---|