perl germanCharProblems.pl -opt wordae="ärgerlich" -opt wordoe="börse" -opt wordue="übersicht" #### #!perl use strict; use warnings; #cpan modules. use Getopt::Long; # Option handling ################### # GLOBAL VARS ################### # Our options my %options; # Grab the options from the command line GetOptions ("opt=s" => \%options); wipe_log(); for (keys %options) { logMessage('$options{' . "$_" . '}' . ": $options{$_} \n" ); } #outputs: #$options{wordoe}: b÷rse #$options{wordue}: ³bersicht #$options{wordae}: õrgerlich for (keys %options) { $options{$_} = strange_dos_chars_to_germanchars($options{$_}); logMessage('$options{' . "$_" . '}' . ": $options{$_} \n" ); } #outputs: #$options{wordoe}: börse #$options{wordue}: übersicht #$options{wordae}: ärgerlich # Takes a variable and spits it back out with the proper german characters sub strange_dos_chars_to_germanchars { my $var = shift; my %table = ( 'ß' => '¯' , 'ä' => 'õ' , 'ö' => '÷' , 'ü' => '³' , 'Ä' => '-' , 'Ö' => 'Í' , 'Ü' => '_'); while (my ($k,$v) = each %table) { $var =~ s/$v/$k/g; } return $var; } sub wipe_log { my $logFileName = "log.txt"; open F, "> $logFileName" or die "Cannot open log file: $logFileName"; close F; } sub logMessage { my $message = shift; my $message = "$message\n"; print $message; # maybe could turn this on and off with command line option. do later? my $logFileName = "log.txt"; open F, ">> $logFileName" or die "Cannot open log file: $logFileName"; print F $message,"\n"; close F; }