Patrick Andrieu: In Hash zwei Arrays einfügen u Ausgabe tätigen

Beitrag lesen

Hallo birgit!

Einfaches Beispiel:

Datei 1.txt:
item1=122
item2=344
item3=556

Datei 2.txt:
item1=123
item2=343
item3=556

--------------

use strict;  
  
my $file1 = "1.txt";  
my $file2 = "2.txt";  
  
open (FILE_1, $file1) or die $!;  
my @FILE_1 = <FILE_1>;  
close FILE_1;  
  
open (FILE_2, $file2) or die $!;  
my @FILE_2 = <FILE_2>;  
close FILE_2;  
  
my %compare_hash = ();  
my @diff1;  
my @diff2;  
for my $i ( 0..2 ) {  
  chomp $FILE_1[$i];  
  chomp $FILE_2[$i];  
  if($FILE_1[$i] ne $FILE_2[$i]) { push (@diff1,$FILE_1[$i]);  
                                   push (@diff2,$FILE_2[$i]);  
                                   $compare_hash{$file1} = \@diff1;  
                                   $compare_hash{$file2} = \@diff2 }  
}  
print "Wo unterscheiden sich die Dateien: \n";  
for (keys %compare_hash) { print "$_ = ";  
                           {local $, = ", "; print @{$compare_hash{$_}}; }  
                           print "\n"; }

--------------

Ausgabe:
Wo unterscheiden sich die Dateien:
1.txt = item1=122, item2=344
2.txt = item1=123, item2=343

Hinweis: Quirk&Dirty und sicher verbesserungswürdig. Ich muss jetzt weg und könnte evtl. Frage erst heute abend beantworten. Aber es sind noch andere hier ;)

Viele Grüße aus Frankfurt/Main,
Patrick

--

_ - jenseits vom delirium - _
[link:hatehtehpehdoppelpunktslashslashwehwehwehpunktatomicminuseggspunktcomslash]
Nichts ist unmöglich? Doch!
Heute schon gegökt?
All'alba vincerò!