#!/usr/bin/perl
# script to replace strings in massive lists of files (good for recode) --alex shevlakov 
# create filelist  with shell command: find ./ -name "*.c" > filez; find ./ -name "*.h" >>filez , etc.
# Then look for files matching strings to be replaced: grep 'string to replace' `cat filez`
# and finally edit the $line1 section at the bottom of the script, run script and delete backup copies (*.bef)
# if everything is fine

$conttype  = "Content-type: text/html\n Charset: koi8-r\n Pragma: no-cache\n\n";
#my @files=('tclub_ru','TClub_LANG_ru.pm');
my @files=('show_active.pl','active_players.pl','check_alert.pl',
'new_players.pl','read_mails.pl','req_ccard.pl','show_kl.pl','show_tourn.pl','update_alert.pl');
	foreach $line (@files) 
		{

		chomp($line);
		$file_name=$line;
		$file_old_name = "$file_name"."\.bef";
		system("mv $file_name $file_old_name");

			
			
			open(OUTF,">$file_name") || print $s=$conttype;
				if ($s eq $conttype) 
				{
					print $file_name;
					exit;
				}
			
			open(INFF,"$file_old_name") || print $s=$conttype;
				if ($s eq $conttype) 
				{
					print $file_name;
					exit;
				}
			@files1=<INFF>;
			
			foreach $line1 (@files1) {
			
			
			
			
$line1=~ s/³/E/g;
$line1=~ s/£/e/g;
$line1=~ s/Ñ/Ñ�/g;
$line1=~ s/Ð/Ð¿/g;

$line1=~ s/á/Ð�/g;
$line1=~ s/â/Ð‘/g;
$line1=~ s/÷/Ð’/g;
$line1=~ s/ç/Ð“/g;
$line1=~ s/ä/Ð”/g;
$line1=~ s/å/Ð•/g;
$line1=~ s/ö/Ð–/g;
$line1=~ s/ú/Ð—/g;
$line1=~ s/é/Ð˜/g;
$line1=~ s/ê/Ð™/g;
$line1=~ s/ë/Ðš/g;
$line1=~ s/ì/Ð›/g;
$line1=~ s/í/Ðœ/g;
$line1=~ s/î/Ð�/g;
$line1=~ s/ï/Ðž/g;
$line1=~ s/ð/ÐŸ/g;
$line1=~ s/ò/Ð /g;
$line1=~ s/ó/Ð¡/g;
$line1=~ s/ô/Ð¢/g;
$line1=~ s/õ/Ð£/g;
$line1=~ s/æ/Ð¤/g;
$line1=~ s/è/Ð¥/g;
$line1=~ s/ã/Ð¦/g;
$line1=~ s/þ/Ð§/g;
$line1=~ s/û/Ð¨/g;
$line1=~ s/ý/Ð©/g;
$line1=~ s/ø/Ð¬/g;
$line1=~ s/ù/Ð«/g;
$line1=~ s/ÿ/Ðª/g;
$line1=~ s/ü/Ð­/g;
$line1=~ s/à/Ð®/g;
$line1=~ s/ñ/Ð¯/g;

$line1=~ s/Á/Ð°/g;
$line1=~ s/Â/Ð±/g;
$line1=~ s/×/Ð²/g;
$line1=~ s/Ç/Ð³/g;
$line1=~ s/Ä/Ð´/g;
$line1=~ s/Å/Ðµ/g;
$line1=~ s/Ö/Ð¶/g;
$line1=~ s/Ú/Ð·/g;
$line1=~ s/É/Ð¸/g;
$line1=~ s/Ê/Ð¹/g;
$line1=~ s/Ë/Ðº/g;
$line1=~ s/Ì/Ð»/g;
$line1=~ s/Í/Ð¼/g;
$line1=~ s/Î/Ð½/g;
$line1=~ s/Ï/Ð¾/g;
$line1=~ s/Ò/Ñ€/g;
$line1=~ s/Ó/Ñ�/g;
$line1=~ s/Ô/Ñ‚/g;
$line1=~ s/Õ/Ñƒ/g;
$line1=~ s/Æ/Ñ„/g;
$line1=~ s/È/Ñ…/g;
$line1=~ s/Ã/Ñ†/g;
$line1=~ s/Þ/Ñ‡/g;
$line1=~ s/Û/Ñˆ/g;
$line1=~ s/Ý/Ñ‰/g;
$line1=~ s/Ø/ÑŒ/g;
$line1=~ s/Ù/Ñ‹/g;
$line1=~ s/ß/ÑŠ/g;
$line1=~ s/Ü/Ñ�/g;
$line1=~ s/À/ÑŽ/g;					
				
				print OUTF $line1;
			}
			
			close(OUTF);
			close(INFF);
			
		system("rm -f $file_old_name");	

		}
	exit;
