#!/usr/bin/perl

($username) = @ARGV;

open (OLD,"users\\$username\\phones0.mlf") || die ("Unable to open file for reading");
open (NEW,">users\\$username\\phonesX.mlf") || die ("Unable to open file for writing");

$find="\"S";
$sub;

while () {
	if(/$find/)	{
		$sub = substr($_, 1, 10);
		print NEW "\"users/$username/$sub\n";
	}
	if (!/$find/) {
		print NEW "$_";
	}
}
close(OLD);
close(NEW);

system ("del users\\$username\\phones0.mlf");
system ("move users\\$username\\phonesX.mlf users\\$username\\phones0.mlf");

open (OLD1,"users\\$username\\words.mlf") || die ("Unable to open file for reading");
open (NEW1,">users\\$username\\wordsX.mlf") || die ("Unable to open file for writing");

$find="\"S";
$sub;

while () {
	if(/$find/)	{
		$sub = substr($_, 1, 10);
		print NEW1 "\"users/$username/$sub\n";
	}
	if (!/$find/) {
		print NEW1 "$_";
	}
}
close(OLD1);
close(NEW1);

system ("del users\\$username\\words.mlf");
system ("move users\\$username\\wordsX.mlf users\\$username\\words.mlf");


open (OLD2,"users\\$username\\phones1.mlf") || die ("Unable to open file for reading");
open (NEW2,">users\\$username\\phonesY.mlf") || die ("Unable to open file for writing");

$find="\"S";
$sub;

while () {
	if(/$find/)	{
		$sub = substr($_, 1, 10);
		print NEW2 "\"users/$username/$sub\n";
	}
	if (!/$find/) {
		print NEW2 "$_";
	}
}
close(OLD2);
close(NEW2);

system ("del users\\$username\\phones1.mlf");
system ("move users\\$username\\phonesY.mlf users\\$username\\phones1.mlf");