Thread Anonyme Arrays miteinander vergleichen. (8 answers)
Opened by toby at 2006-08-28 02:29

topeg
 2006-08-28 09:54
#69265 #69265
User since
2006-07-10
2611 Artikel
BenutzerIn

user image
in deinem fall würde ich auf "Data::Dumper" zurückgreifen, da die gesammte Struktur verglichen werden soll.
Hier meine Variante:
Code: (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
#!/usr/bin/perl

use strict;
use warnings;
use Data::Dumper;
$Data::Dumper::Indent=0;

# Master-Array
my $master = [
{ x => ['1','a'], y => [], z => ['4'], },
{ x => ['b','a'], y => ['1','a'], z => ['1'], },
{ x => ['1','a'], y => [], z => [1], },
{ x => [], y => ['a','1'], z => ['2'], },
];

# autonome Hashes
my $h1 = { x => ['1','a'] , y => [] , z => ['4'] };
my $h2 = { x => ['a'] , y => [] , z => ['1'] };
my $h3 = { x => ['1'] , y => ['a',1] , z => [2] };
my $h4 = { x => [] , y => ['a1'] , z => ['1','2'] };

my @checkit = ($h1,$h2,$h3,$h4);
my $hrefCount;

foreach my $href (@checkit){
$hrefCount++;
masterElemente($href);
printf "ende von hrefCount: %s\n",$hrefCount;
};

sub masterElemente
{
my $href = shift;
my $skey_suche=Dumper($href);
for my $pos (0..$#{$master})
{
my $skey_master=Dumper($$master[$pos]);
if($skey_master eq $skey_suche)
{
print "BINGO im Element an der Position $pos (".@{$master}." Elemente)!\n";
last;
}
}
}

View full thread Anonyme Arrays miteinander vergleichen.