Thread Array of Arrays (Matrix vs. Tabelle) (4 answers)
Opened by kimmy at 2011-12-22 15:56

moritz
 2011-12-22 18:49
#155028 #155028
User since
2007-05-11
923 Artikel
HausmeisterIn
[Homepage]
user image
Also zuerst mal benutzt mit my ... if ... ; ein sehr gefährliches Konstrukt. Perldoc:perlsyn sagt dazu:

Quote
NOTE: The behaviour of a "my" statement modified with a statement
modifier conditional or loop construct (e.g. "my $x if ...") is
undefined. The value of the "my" variable may be "undef", any
previously assigned value, or possibly anything else. Don't rely on
it. Future versions of perl might do something different from the
version of perl you try it out on. Here be dragons.


Also lass das lieber.

Ich verstehe auch ehrlich gesagt deinen Code nicht, ich finde den zu kompliziert. Ich würde eher so etwas hier machen:

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
use warnings;

my @data;

sub numeric_idx {
    my $val = shift;
    return ord($val) - ord('A');
}

while (<DATA>) {
    chomp;
    my ($x, $y, $v) = split /\t/;
    $data[numeric_idx($x)][numeric_idx($y)] = $v if defined $v;
}


__DATA__
A       A
B       A       1
C       A       3
C       B       2
D       A       2
D       B       4
D       C       3

View full thread Array of Arrays (Matrix vs. Tabelle)