moff has asked for the wisdom of the Perl Monks concerning the following question:
English and translated strings are separated by a tab character. I found this and managed to put together the following code to read the file into a hash array:Retire a document Dokument deaktivieren Remove a document from the knowledge base Dokument aus der Knowledg +e Base entfernen Promote document retirement Dokument deaktivieren Document Expired Dokument abgelaufen
As far as I can tell, the hash is created correctly (otherwise please tell me), and the keys are populated by the English strings and the values by the translated ones.use strict; use warnings; open (FILE, "extract_tab.txt") or die "$!\n"; my %hash; while (my $line = <FILE>) { chomp($line); my ($enu, $deu) = split /\t/, $line; $hash{$enu} = $deu; } for my $key (keys %hash) { print "$key\n"; } for my $value (values %hash) { print "$value\n"; }
I now want to identify those keys that have identical values, and print them out. Something like "English strings 'Retire a document' and 'Promote document retirement' have the same translation ('Dokument deaktivieren')". I have been trying along the lines of the answers provided to this post, but I am getting stuck.
is giving me this error: Can't use string ("Dokument aus der Knowledge Base ") as a HASH ref while "strict refs" in use at hashtest.pl line 18, <FILE> line 4. Could someone help me understand? Or any hints for a different approach if it makes things easier? Thanks.#my %seen; for my $key (keys %hash) { my $value_key = "@{[values %{$hash{$key}}]}"; #print "$value_key\n"; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Find duplicate values in hash
by JavaFan (Canon) on Apr 10, 2009 at 17:12 UTC | |
Re: Find duplicate values in hash
by FunkyMonk (Chancellor) on Apr 10, 2009 at 17:23 UTC | |
Re: Find duplicate values in hash
by toolic (Bishop) on Apr 10, 2009 at 17:24 UTC | |
Re: Find duplicate values in hash
by Nkuvu (Priest) on Apr 10, 2009 at 17:22 UTC | |
Re: Find duplicate values in hash
by whakka (Hermit) on Apr 10, 2009 at 21:25 UTC | |
by moff (Novice) on Apr 11, 2009 at 13:25 UTC | |
by moff (Novice) on Apr 17, 2009 at 19:17 UTC |