#!/usr/bin/perl -w # file1=regras.pt-br file2=regras.pt-brao file3=regras.br-brao #André Santos, Ago2009 use feature "say"; $file1 = shift; open (HASH, $file1) or die("can find $file1\n"); my (%hash); while (){ if (/^(.*?)\s*\/(.*?)\s*\/(.*?)\s*$/){ my $key = $1; my @br = split(/,/, $3); my $value = shift @br; $value =~ s/^\s+|\s+$//g; $hash{$key} = $value;} } close(HASH); $file2 = shift; $file3 = shift; my $replaced = 0; open(DICT, $file2); open(NOVO, ">$file3"); while ($line = ){ if ($line =~ /^(.*?)(\/.*?)\s*$/){ chomp $line; if (defined($nova = $hash{$1})){ say NOVO "$nova$2"; $replaced++;} #else {print NOVO $line;} } #else {print NOVO $line;} } close(DICT); close(NOVO); say STDERR "Substituições: $replaced";