Perl Dokument bekommt Werte vom vorher bearbeiteten Dokument

nico_wagner

Cadet 3rd Year
Registriert
Nov. 2013
Beiträge
59
Hallo,
ich schreibe ein Programm zur Verschlüsselung von Daten.
Das als erstes bearbeitetes Dokument funktioniert tadellos. Jedoch werden die Zeilen aus dem ersten im zweiten Dokument übernommen. Kann mir jemand helfen?
Hier ist der Code:

Code:
use Digest::MD5 qw(md5_hex);

$rand = srand();
start ();


while($z eq "y")	
{
	search();
	files();
}	
	
	sub search{
	print "Enter source directory name:\n\n";
	chomp($x = <STDIN>);
	$x =~ s/\\$//;						
 
	if(-e $x."\\orig\\perf")			
	{							
 
		if(!(-e $x."\edit"))			
		{				
			system("mkdir $x\\edit");
		}
 
		if(!(-e $x."\edit\perf"))
		{
			system("mkdir $x\\edit\\perf");		
		}
 
		system("copy $x\\orig\\perf\\* $x\\edit\\perf");	
	}

	if(-e $x."\\orig\\cdr")
	{

		if(!(-e $x."\edit"))
		{		
			system("mkdir $x\\edit");
		}
	 
		if(!(-e $x."\edit\cd"))
		{
			system("mkdir $x\\edit\\cdr");		
		}
	 
		system("copy $x\\orig\\cdr\\* $x\\edit\\cdr");
	}	

	if(-e $x."\\orig\\inv")
	{				
	 
		if(!(-e $x."\edit"))
		{				
			system("mkdir $x\\edit");
		}
	 
		if(!(-e $x."\edit\inv"))
		{
			system("mkdir $x\\edit\\inv");		
		}
	 
		system("copy $x\\orig\\inv\\* $x\\edit\\inv");
	}
	}	


	sub files{
	while($file = glob("C:\\Users\\nwagner7\\Documents\\anonymisierung\\edit\\cdr\\*.csv")){
		print "cdr go \n";
		Crypt();
	}
	while($file = glob("C:\\Users\\nwagner7\\Documents\\anonymisierung\\edit\\perf\\*.csv")){
		print "perf go \n";
		Crypt();
	}
	while($file = glob("C:\\Users\\nwagner7\\Documents\\anonymisierung\\edit\\inv\\*.csv")){
		print "inv go \n";
		Crypt();
	}
	}
	
	sub Crypt{
		open(DAT, "$file") or die "$!";	
		while ($line=<DAT>) {
			push (@record,$line);
		}	

		close(DAT);
		open(CSV,">$file");
		$anzahl = @record;

	
		if($file =~ /cdr/){
			print "cdr \n";
			for($i = 0; $i < $anzahl; $i++)	{
				$t = @record[$i];
				$t =~ tr/|/;/;
				@array=split(/;/,$t);
				@hashed[$i] = md5_hex(@array[3], $rand);
				@array[3] = @hashed[$i];
				@hashed[$i] = md5_hex(@array[4], $rand);
				@array[4] =  @hashed[$i];
				$string  = join ('|' , @array);
				print $string;
				print CSV  $string;	
			}
		}
		else	{		
				
				if($file =~ /pmn.cl_perf/)	
				{
					print "perf \n";
					for($i = 0; $i < $anzahl; $i++)	
					{
						print $string;
						print $anzahl;
						$t = @record[$i];
						$t =~ tr/|/;/;
						@array=split(/;/,$t);
						@ausgabe = @array;
						@hashed[$i] = md5_hex(@array[48], $rand);
						@array[48] = @hashed[$i];
						$string  = join ('|' , @array);
						print $string;
						print CSV  $string;	
					}
				}
			#	else{
			#		if($file =~ /pmn.cl_inv/)	{
			#			print "inv \n";
			#			for($i = 0; $i < $anzahl; $i++)	{
			#				$t = @record[$i];
			#				@array=split(/;/,$t);
			#				@ausgabe = @array;
			#				@hashed[$i] = md5_hex(@array[48], $rand);
			#				@array[48] = @hashed[$i];
			#				$string  = join ('|' , @array);
			#				print CSV  $string;	
			#			}
			#		}
			#	}
		}
	
		close(CSV);
	}




sub start{

print ("Do you want to anomize any Data? Type y for yes or any other button to cancel:\n");
chomp($z = <STDIN>);
}
 
Zunächst: Perl ist meine erste Script Sprache die ich jetzt seit einer Woche versuche zu lernen...Werde die zwar hinterher nicht mehr rbauchen aber egal...Ja das habe ich mir auch gedacht und folgendes ohne Erfolg probiert:

Code:
while(@array)
		{
			shift(@array);			
		}
		while(@hashed)
		{
			shift(@hashed)
		}
		while(@ausgabe)
		{
			shift(@ausgabe)
		}
		while(@anzahl)
		{
			shift(@anzahl)
		}
		
		$string = undef;
Ergänzung ()

Problem gelöst! Habe es nun mit @array = (); gelöst. Aber wenn es eine bessere Lösung gibt, würde ich diese gerne hören!
 
Zurück
Oben