Thread Precedences und Schönheit (21 answers)
Opened by RalphFFM at 2018-03-31 14:27

rosti
 2018-03-31 18:08
#188199 #188199
User since
2011-03-19
3194 Artikel
BenutzerIn
[Homepage]
user image
Sorry, mein Fehler, hier nun richtig:

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
use strict;
use warnings;
use Tie::Scalar;
use base qw(Tie::StdScalar);

sub TIESCALAR{
    my $class = shift;
    my $init = shift || 1;
    bless \$init, $class
}

sub FETCH{
    my $self = shift;
    print "FETCH: $$self\n";
    $$self;
}


tie my $i, 'main', 1;
$i = $i < 5 ? ++$i : 1;

print "Finale: $i\n";

# Ausgabe
FETCH: 1
FETCH: 1
FETCH: 2
Finale: 2



Also: Was $i = $i < 5 ? ++$i : 1; wirklich macht sehen wir nun.

Das andere Beispiel
Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
++$i for 1..5;

# Gibt aus:
FETCH: 1
FETCH: 2
FETCH: 3
FETCH: 4
FETCH: 5
FETCH: 6
Finale: 6


Was ich auch erwartet hätte.

.
Last edited: 2018-03-31 18:12:49 +0200 (CEST)

View full thread Precedences und Schönheit