der aktuelle Stand Perl 5.20 an features und Kultur: beeinflusst von Perl 6 wird an den wesentlichen Stellen aufgeräumt: dies war das Update für den Linuxtag in Chemnitz März 2015
1. Perl heute
This package has never done
anything and never will do
anything. If it changes,
that's a bug.
Please report it to
mst@shadowcat.co.uk where I
will proceed to ignore it.
95. Array/S. Kontext
my @array = ('d' .. 'f');
say @array; # alle Werte eines Array : d e f
say @array[0,1]; # Teilarray mit zwei Werten : d e
say $array[2]; # ein Wert aus gleichen Var.: f
96. A./Skalar Kontext
my @array = ('d' .. 'f');
say @array; # alle Werte eines Array : d e f
say @array[0,1]; # Teilarray mit zwei Werten : d e
say $array[2]; # ein Wert aus gleichen Var.: f
my %hash = (a => 1, b => 2, c => 3 );
say %hash; # alle Schlüssel & Werte: a 1 b 2 c 3
say @hash{'a','b'}; # Werten zweier Schlüssel: 1 2
say $hash{'c'}; # Wert des Schlüssels: 3
97. Pair Slices
my @array = ('d' .. 'f');
my %hash = (a => 1, b => 2, c => 3 );
say %array[0,1]; # im Wechsel Index/Wert: 0 d 1 e
say %hash{'a','b'}; # Schlüssel/Wert: a 1 b 2
98. Pair Slices
my @array = ('d' .. 'f');
my %hash = (a => 1, b => 2, c => 3 );
say %array[0,1]; # im Wechsel Index/Wert: 0 d 1 e
say %hash{'a','b'}; # Schlüssel/Wert: a 1 b 2
Perl 6:
say @array[0,1] :p; # Ausgabe: 0 => "d" 1 => "e"
say %hash<'a','b'> :p; # Ausgabe: "a" => 1 "b" => 2
99. Pair Slices on Ref
my $arrayref = ['d' .. 'f'];
my $hashref = {a => 1, b => 2, c => 3 };
say %$arrayref[0,1]; # Index/Wert: 0 d 1 e
say %$hashref{'a','b'}; # Schlüssel/Wert: a 1 b 2
107. Postfix-Deref.
$array[2][7]; # ein Wert, wie bekannt
$array[2]->[7]; # dasselbe
$array[2]->@[7]; # kein Vorteil soweit
$array[2]->@[5,6]; # 2 Werte, gleichbedeutend mit:
@{$array[2]}[5,6]; # ging bisher nur so
$array[2]->%[5,6]; # auch Pair Slices möglich
$hash{'a'}->%{'g','e'}; # bei verschachtelten Hashes
108. Postfix-Deref.
$array[2][7]; # ein Wert, wie bekannt
$array[2]->[7]; # dasselbe
$array[2]->@[7]; # kein Vorteil soweit
$array[2]->@[5,6]; # 2 Werte, gleichbedeutend mit:
@{$array[2]}[5,6]; # ging bisher nur so
$array[2]->%[5,6]; # auch Pair Slices möglich
$hash{'a'}->%{'g','e'}; # bei verschachtelten Hashes
$array[2]->@* # gesamter Unterarrayinhalt
$array[2]->$#* # Anzahl der Elemente
109. Postfix-Deref.
$array[2][7]; # ein Wert, wie bekannt
$array[2]->[7]; # dasselbe
$array[2]->@[7]; # kein Vorteil soweit
$array[2]->@[5,6]; # 2 Werte, gleichbedeutend mit:
@{$array[2]}[5,6]; # ging bisher nur so
$array[2]->%[5,6]; # auch Pair Slices möglich
$hash{'a'}->%{'g','e'}; # bei verschachtelten Hashes
$array[2]->@* # gesamter Unterarrayinhalt
$array[2]->$#* # Anzahl der Elemente
$array[2]->*{ARRAY} # GLOB / symbol Tabelle
110. Postfix-Deref.
$array[2][7]; # ein Wert, wie bekannt
$array[2]->[7]; # dasselbe
$array[2]->@[7]; # kein Vorteil soweit
$array[2]->@[5,6]; # 2 Werte, gleichbedeutend mit:
@{$array[2]}[5,6]; # ging bisher nur so
$array[2]->%[5,6]; # auch Pair Slices möglich
$hash{'a'}->%{'g','e'}; # bei verschachtelten Hashes
$array[2]->@* # gesamter Unterarrayinhalt
$array[2]->$#* # Anzahl der Elemente
$array[2]->*{ARRAY} # GLOB / symbol Tabelle
“$hash{a}->%{g,e}” # sogar interpoliert
145. M Dokumentation
This package has never done
anything and never will do
anything. If it changes,
that's a bug.
Please report it to
mst@shadowcat.co.uk where I will
proceed to ignore it.