Advertisement

05.22.2008 at 03:33PM PDT, ID: 23426127
[x]
Attachment Details

File processing and XML::Simple hash table problem

Asked by acrxx in Perl Programming Language

Hi Everyone,

I am having some serious problem using lines from a file as hash table references, they simply will not work. The files contain attributes which are present within the XML file being read in, one per line. It worked fine as ling as I only used <myFile>, but after I added the second file <myGroupsFile>, it failed to read from the XML::Simple hash data object.

Any ideas where problem may lie?

AndyStart Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
#!/usr/bin/perl -w
 
use strict;
use utf8;
use XML::Simple;
use LWP::Simple;
use Encode;
 
 
sub main {
	my $ref = XMLin("language_propertiesALL.xml");
 
	my $longestString = "";
	my $currentString = "";
	my $currentLongestLang = "";
 
	open myFile, "allPropertyNames.txt";
    while(chomp(my $line = <myFile>)) {
		
		open myGroupsFile, "groups.txt";
		while(chomp(my $groupsline = <myGroupsFile>)) {
			if( exists $ref->{'configuration'}->{'all'}->{'properties'}[0]->{'languageproperty'}->{$line}->{'group'}->{$groupsline}->{'languagecode'}->{'en'}->{'content'})
			{
				$currentString = $ref->{'configuration'}->{'all'}->{'properties'}[0]->{'languageproperty'}->{$line}->{'group'}->{$groupsline}->{'languagecode'}->{'en'}->{'content'};
 
				if(length($currentString) > length($longestString))
				{
					$longestString = $currentString;
					$currentLongestLang = "en";
				}
			}
			if( exists $ref->{'configuration'}->{'all'}->{'properties'}[0]->{'languageproperty'}->{$line}->{'group'}->{$groupsline}->{'languagecode'}->{'ro'}->{'content'})
			{
			print "bla";
				$currentString = $ref->{'configuration'}->{'all'}->{'properties'}[0]->{'languageproperty'}->{$line}->{'group'}->{$groupsline}->{'languagecode'}->{'ro'}->{'content'};
 
				if(length($currentString) > length($longestString))
				{
					$longestString = $currentString;
					$currentLongestLang = "ro";
				}
			}
			if( exists $ref->{'configuration'}->{'all'}->{'properties'}[0]->{'languageproperty'}->{$line}->{'group'}->{$groupsline}->{'languagecode'}->{'es'}->{'content'})
			{
			print "bla";
				$currentString = $ref->{'configuration'}->{'all'}->{'properties'}[0]->{'languageproperty'}->{$line}->{'group'}->{$groupsline}->{'languagecode'}->{'es'}->{'content'};
 
				if(length($currentString) > length($longestString))
				{
					$longestString = $currentString;
					$currentLongestLang = "es";
				}
			}
			if( exists $ref->{'configuration'}->{'all'}->{'properties'}[0]->{'languageproperty'}->{$line}->{'group'}->{$groupsline}->{'languagecode'}->{'cs'}->{'content'})
			{
			print "bla";
				$currentString = $ref->{'configuration'}->{'all'}->{'properties'}[0]->{'languageproperty'}->{$line}->{'group'}->{$groupsline}->{'languagecode'}->{'cs'}->{'content'};
 
				if(length($currentString) > length($longestString))
				{
					$longestString = $currentString;
					$currentLongestLang = "cs";
				}
			}
			if( exists $ref->{'configuration'}->{'all'}->{'properties'}[0]->{'languageproperty'}->{$line}->{'group'}->{$groupsline}->{'languagecode'}->{'el'}->{'content'})
			{
			print "bla";
				$currentString = $ref->{'configuration'}->{'all'}->{'properties'}[0]->{'languageproperty'}->{$line}->{'group'}->{$groupsline}->{'languagecode'}->{'el'}->{'content'};
 
				if(length(decode_utf8($currentString)) > length($longestString))
				{
					$longestString = $currentString;
					$currentLongestLang = "el";
				}
			}
			
		}
close(myGroupsFile);
		if( not $longestString eq "")
		{
			print "$line";
			print "~";
			print "$currentLongestLang";
			print "~";
			print "$longestString";
			print "\n";
		}
        
    }
close(myFile);
}
main();
[+][-]05.22.2008 at 07:22PM PDT, ID: 21629013

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.22.2008 at 10:56PM PDT, ID: 21629644

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Perl Programming Language
Sign Up Now!
Solution Provided By: oleber
Participating Experts: 2
Solution Grade: A
 
 
[+][-]05.25.2008 at 06:28AM PDT, ID: 21642556

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628