Thread Syntax Zugriff Array Index (23 answers)
Opened by bianca at 2019-08-11 08:23

FIFO
 2019-08-11 14:59
#190360 #190360
User since
2005-06-01
469 Artikel
BenutzerIn

user image
Zwei Dinge muss man allerdings bedenken:
* Bei (sehr) großen Arrays kann das länger als nötig dauern
* Die Formulierung ist nicht gut lesbar. Nach 6 Wochen muss ich idR zweimal hinschauen um zu begreifen, was so eine Zeile machen sollte. Hab mir angewöhnt, defensiv zu formulieren, hier z.B. als for-Iteration:

Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
for my $item ( @stats ) {
    if ( $item->[0] eq 'RequestsD' ) {
        $item->[1]++;       # @stats wir inplace verändert
    }
}

# oder postfix:

for my $item ( @stats ) {
    $item->[1]++ if $item->[0] eq 'RequestsD';
}
Everyone knows that debugging is twice as hard as writing a program in the first place. So if you're as clever as you can be when you write it, how will you ever debug it? -- Brian Kernighan: "The Elements of Programming Style"

View full thread Syntax Zugriff Array Index