Thread zwei Arrays vergleichen und doppelten Inhalt löschen (31 answers)
Opened by Matze2.pl at 2014-11-13 10:27

GwenDragon
 2014-11-13 16:20
#178343 #178343
User since
2005-01-17
14783 Artikel
Admin1
[Homepage]
user image
Code (perl): (dl )
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;

use Data::Printer;


my @a = (1,2,3,4);
my @b = (1,3,2,5,6);
p(@a);
p(@b);
my %h = map { $_ => 1 } @a;
p(%h);
@b = grep { ! exists $h{$_} } @b;
p(@a);
p(@b);

__END__
ergibt:

[
    [0] 1,
    [1] 2,
    [2] 3,
    [3] 4
]
[
    [0] 1,
    [1] 3,
    [2] 2,
    [3] 5,
    [4] 6
]

{
    1   1,
    2   1,
    3   1,
    4   1
}

[
    [0] 1,
    [1] 2,
    [2] 3,
    [3] 4
]
[
    [0] 5,
    [1] 6
]

View full thread zwei Arrays vergleichen und doppelten Inhalt löschen