Hello, I have a file which looks like this:
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
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:
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"; }
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.

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.

#my %seen; for my $key (keys %hash) { my $value_key = "@{[values %{$hash{$key}}]}"; #print "$value_key\n"; }
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.

In reply to Find duplicate values in hash by moff

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.