Thread Array mit Werten auffüllen (16 answers)
Opened by sebi85 at 2010-12-14 11:41

Gast wer
 2010-12-15 09:32
#143592 #143592
Missverständis des Code. "@add" enthält temporäre Werte, die in "@tmp_container" ergänzt werden wenn sie fehlen:

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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;

my @tmp_container=();

$tmp_container[0]->[0]->[0] = 'CIS';
$tmp_container[0]->[0]->[1] = 'P1';
$tmp_container[0]->[0]->[2] = 'A1';
$tmp_container[0]->[1]->[0] = 'off';
$tmp_container[0]->[2]->[0] = 'AAA';
$tmp_container[0]->[2]->[1] = 'xxx';
$tmp_container[0]->[3]->[0] = 'on';
#------------------------------------
$tmp_container[1]->[0]->[0] = 'AAA';
$tmp_container[1]->[0]->[1] = 'yyy';
$tmp_container[1]->[1]->[0] = 'on';
#------------------------------------
$tmp_container[2]->[0]->[0] = 'AAA';
$tmp_container[2]->[0]->[1] = 'zzz';
$tmp_container[2]->[1]->[0] = 'on';
#------------------------------------
$tmp_container[3]->[0]->[0] = 'BBB';
$tmp_container[3]->[0]->[1] = 'xxx';
$tmp_container[3]->[1]->[0] = 'on';
#------------------------------------
$tmp_container[4]->[0]->[0] = 'BBB';
$tmp_container[4]->[0]->[1] = 'yyy';
$tmp_container[4]->[1]->[0] = 'on';
#------------------------------------
$tmp_container[5]->[0]->[0] = 'BBB';
$tmp_container[5]->[0]->[1] = 'zzz';
$tmp_container[5]->[1]->[0] = 'on';

#------------------------------------
$tmp_container[6]->[0]->[0] = 'CIS';
$tmp_container[6]->[0]->[1] = 'P1';
$tmp_container[6]->[0]->[2] = 'A2';
$tmp_container[6]->[1]->[0] = 'off';
$tmp_container[6]->[2]->[0] = 'AAA';
$tmp_container[6]->[2]->[1] = 'xxx';
$tmp_container[6]->[3]->[0] = 'on';
#------------------------------------
$tmp_container[7]->[0]->[0] = 'AAA';
$tmp_container[7]->[0]->[1] = 'yyy';
$tmp_container[7]->[1]->[0] = 'on';
#------------------------------------
$tmp_container[8]->[0]->[0] = 'AAA';
$tmp_container[8]->[0]->[1] = 'zzz';
$tmp_container[8]->[1]->[0] = 'on';
#------------------------------------
$tmp_container[9]->[0]->[0] = 'BBB';
$tmp_container[9]->[0]->[1] = 'xxx';
$tmp_container[9]->[1]->[0] = 'on';
#------------------------------------

#print Dumper(\@tmp_container);

my @add;
for my $arr (@tmp_container)
{
  if(@{$arr->[0]}>2)
  {
    @add=($arr->[0],$arr->[1]);
  }
  else
  {
    my @add1=@{$add[0]};
    my @add2=@{$add[1]};
    unshift(@{$arr},\@add1,\@add2);
  }
}

#print Dumper(\@tmp_container);

print "\n1: ".$tmp_container[0]."\n";
print "\n2: ".$tmp_container[0]->[0]."\n";
print "\n3: ".$tmp_container[0]->[0]->[0]."\n";

print "\n1: ".$tmp_container[1]."\n";
print "\n2: ".$tmp_container[1]->[0]."\n";
print "\n3: ".$tmp_container[1]->[0]->[0]."\n";

print "\n1: ".$tmp_container[2]."\n";
print "\n2: ".$tmp_container[2]->[0]."\n";
print "\n3: ".$tmp_container[2]->[0]->[0]."\n";

Last edited: 2010-12-15 09:55:28 +0100 (CET)

View full thread Array mit Werten auffüllen