Leser: 2
|< 1 2 3 >| | 23 Einträge, 3 Seiten |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
my @bla;
open(my $fh,"<A.txt") or die $!;
my @lines_a = <$fh>;
close $fh;
open(my $fh_b,"<B.txt") or die $!;
while(my $line = <$fh_b>){
chomp $line;
next if($line =~ /^\s*$/);
my @info = split /\s+/,$line;
my @info_a = split /\s+/,$lines_a[$.-1];
if($info[0] == $info_a[0]){
for(1..4){
my $string = $info[$_] eq $info_a[$_] ? "gleich" : "ungleich";
push(@bla,[$.,$info[$_],$info_a[$_],$string]);
}
}
}
close $fh_b;
print Dumper(\@bla);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/perl
use strict;
use warnings;
my $file_a = <<EO_FILE_A;
a b c d e
f g h i j
k l m n o
x q y w z
EO_FILE_A
my $file_b = <<EO_FILE_B;
a b c f e
k o j n p
y w e q a
x q y w z
EO_FILE_B
open( FILE_A, '<', \$file_a ) or die $!;
open( FILE_B, '<', \$file_b ) or die $!;
my $pattern = qr/^\s*$/; # trifft auf leere Zeilen oder nur Whitespaces zu
my @lines_a = grep !/$pattern/, <FILE_A>;
my @lines_b = grep !/$pattern/, <FILE_B>;
close( FILE_A ); close( FILE_B );
chomp(@lines_a, @lines_b);
for( my $i = 0; defined $lines_a[$i] && defined $lines_b[$i]; $i++ ) {
my @parts_a = split /\s+/, $lines_a[$i];
my @parts_b = split /\s+/, $lines_b[$i];
next unless $parts_a[0] eq $parts_b[0]; # ueberspringt ungleiche Satznr.
print "\t\t$lines_a[$i]\t$lines_b[$i]\n";
print "Satznr: $parts_a[0]\n";
print "Aufeinanderfolgend gleiche Woerter:";
# so lange beide Elemente definiert sind und gleiche Inhalte haben ...
my $j = 1;
while( (defined $parts_a[$j] && defined $parts_b[$j])
&& ($parts_a[$j] eq $parts_b[$j]) ) {
print " $j"; # ... aktuelle Wortindexnr. ausgeben
$j++;
}
print "\n", '-' x 45, "\n\n";
}
|< 1 2 3 >| | 23 Einträge, 3 Seiten |