fix line endings of translate.pl

This commit is contained in:
Thomas Bernard 2018-06-21 15:32:22 +02:00
parent 3d922261e1
commit f8de20fc8d

View File

@ -1,52 +1,52 @@
#!/usr/bin/perl #!/usr/bin/perl
# Translate words in file(s) given on command-line. Saves older as .bak # Translate words in file(s) given on command-line. Saves older as .bak
# The dictionary is read as 2 files, french.txt and english.txt # The dictionary is read as 2 files, french.txt and english.txt
# Method: regexp search, ^word then ^non-word then ^word then ... # Method: regexp search, ^word then ^non-word then ^word then ...
# Each word is translated according to a hash dictionary # Each word is translated according to a hash dictionary
# Released to public domain. # Released to public domain.
unless ( open (FRENCH, "french.txt")) { unless ( open (FRENCH, "french.txt")) {
die "Impossible to open 'french.txt' file.\n"; die "Impossible to open 'french.txt' file.\n";
} }
unless ( open (ENGLISH, "english.txt")) { unless ( open (ENGLISH, "english.txt")) {
die "Impossible to open 'english.txt' file.\n"; die "Impossible to open 'english.txt' file.\n";
} }
# Build french->english dictionary (a hash) # Build french->english dictionary (a hash)
while(($french = <FRENCH>) & ($english=<ENGLISH>)){ while(($french = <FRENCH>) & ($english=<ENGLISH>)){
chop($french); chop($french);
chop($english); chop($english);
if ("$french" ne "$english") if ("$french" ne "$english")
{ {
$dictionary{$french} = $english; $dictionary{$french} = $english;
} }
} }
#foreach $name (@ARGV) { #foreach $name (@ARGV) {
#print "$name"; #print "$name";
$^I = ".bak"; $^I = ".bak";
# Read input # Read input
while ($line = <>){ while ($line = <>){
chop $line; chop $line;
while ($line ne "") { while ($line ne "") {
# word # word
if ($line =~ m/^(\w+)(.*)$/) { if ($line =~ m/^(\w+)(.*)$/) {
if (defined $dictionary{$1}) { if (defined $dictionary{$1}) {
print $dictionary{$1}; print $dictionary{$1};
} }
else { else {
print "$1"; print "$1";
} }
$line=$2; $line=$2;
} }
# non-word # non-word
if ($line =~ m/^([^\w]+)(.*)$/) { if ($line =~ m/^([^\w]+)(.*)$/) {
print "$1"; print "$1";
$line=$2; $line=$2;
} }
} }
print "\n"; print "\n";
} }
#} #}