Hallo Community! :)
beim programmieren bin ich auf ein seltsames Verhalten beim 'and' nach einer autovivication gestossen. Hab daraufhin folgendes Code vorbereitet, der dieses Verhalten illustrieren soll. Wer kann mir also folgendes (für mich sehr, sehr seltsames) Verhalten erklären.
Der Code:
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
#!/usr/bin/perl
use strict;
use warnings;
my $arg = shift;
my %blah;
for my $lauf (1..3){
#a)
if ( $arg eq 'a' ) {
printf "$lauf. vor ++\n";
$blah{$lauf}++;
printf "$lauf. nach ++\n";
next;
}
#b)
if ( $arg eq 'b' ) {
printf "$lauf. vor ++\n" and
$blah{$lauf}++ and
printf "$lauf. nach ++\n" and
next;
}
#c)
printf "$lauf. vor ++\n" and $blah{$lauf}++ and printf "$lauf. nach ++\n" and next if ( $arg eq 'c');
}
foreach(keys %blah){
print "hier spricht die autovivication vom lauf $_ fuer $arg\n";
}
print "END\n";
Das Verhalten:
Quote$ perl autovivication_with_and.pl a
1. vor ++
1. nach ++
2. vor ++
2. nach ++
3. vor ++
3. nach ++
hier spricht die autovivication vom lauf 1 fuer a
hier spricht die autovivication vom lauf 3 fuer a
hier spricht die autovivication vom lauf 2 fuer a
END
$ perl autovivication_with_and.pl b
1. vor ++
2. vor ++
3. vor ++
hier spricht die autovivication vom lauf 1 fuer b
hier spricht die autovivication vom lauf 3 fuer b
hier spricht die autovivication vom lauf 2 fuer b
END
$ perl autovivication_with_and.pl c
1. vor ++
2. vor ++
3. vor ++
hier spricht die autovivication vom lauf 1 fuer c
hier spricht die autovivication vom lauf 3 fuer c
hier spricht die autovivication vom lauf 2 fuer c
END
Warum fehlen bei 'b' und 'c' die durch 'and' in der Rheie geschalteten Ausgaben, wie es der Fall bei 'a' ist? Die incrementierung ist aber auf jeden Fall erfolgt... *confused*
Wer kann das erklären?
TIA
Toby\n\n
<!--EDIT|toby|1185395813-->