in reply to Remove duplicate words from a dictionary

my %mapping; while (<>) { my ($key, $value) = /^(.*?)=(.*)$/ or die "Cannot parse $_"; $mapping{$key}{$_} = 1 for split /, /, $value; } for my $word (sort keys %mapping) { my @aliases = sort keys %{$mapping{$word}}; print "$word=", join(", ", @aliases), "\n"; }

update: Yeah, I wanted it to be a HoH, fixed the code, sorry.

Replies are listed 'Best First'.
Re^2: Remove duplicate words from a dictionary
by 1Nf3 (Pilgrim) on Dec 27, 2006 at 23:14 UTC
    Thank you. Tomorrow I will test it against my 500k data file, but I'm sure it's just the thing I needed. Thank you for the solution, and thank you for the books. I would say "the books that had taught me everything I know about Perl", but as you see, I don't know much, so I'll write this: Thanks for the great books you wrote, for if I don't know much about Perl, it's not their fault.
Re^2: Remove duplicate words from a dictionary
by polettix (Vicar) on Dec 28, 2006 at 10:16 UTC
    %mapping seems to be a HoH in the first cycle, and a HoA in the second. I'd probably modify to (untested):
    my %mapping; while (<>) { my ($key, $value) = /^(.*?)=(.*)$/ or die "Cannot parse $_"; push @{$mapping{$key}}, split /, /, $value; } for my $word (sort keys %mapping) { my @aliases = sort @{$mapping{$word}}; print "$word=", join(", ", @aliases), "\n"; }
    or, if scared by possible repetitions (untested, again):
    my %mapping; while (<>) { my ($key, $value) = /^(.*?)=(.*)$/ or die "Cannot parse $_"; $mapping{$key}{$_} = 1 for split /, /, $value; } for my $word (sort keys %mapping) { my @aliases = sort keys %{$mapping{$word}}; print "$word=", join(", ", @aliases), "\n"; }

    Flavio
    perl -ple'$_=reverse' <<<ti.xittelop@oivalf

    Don't fool yourself.