Thread Subroutine als Parameter: Syntax Verständnisproblem (11 answers)
Opened by Perl007 at 2018-06-28 09:40

GwenDragon
 2018-06-28 11:04
#188574 #188574
User since
2005-01-17
14598 Artikel
Admin1
[Homepage]
user image
Mojo::IOLoop->server({parameter, wert}, sub { … });
Das ist so zu verstehen, dass server() mit zwei Parametern aufgerufen wird, einem Hash (beinhaltet mehrere zu konfigurierende Werte für den Server) und einer Funktion (welche die Request behandelt).

Quote
The => operator (sometimes pronounced "fat comma") is a synonym for the comma except that it causes a word on its left to be interpreted as a string if it begins with a letter or underscore and is composed only of letters, digits and underscores. This includes operands that might otherwise be interpreted as operators, constants, single number v-strings or function calls. If in doubt about this behavior, the left operand can be quoted explicitly.

Otherwise, the => operator behaves exactly as the comma operator or list argument separator, according to context.

http://perldoc.perl.org/perlop.html#Comma-Operator

Der =>-Operator (auch "Fat Comma" genannt) ist im Grunde genommen dazu da, besser zu beschreiben, welche Wertepaare zusammengehören.
Außerdem erzwingt ein => dass der linke Parameter als Zeichenkette angesehen wird, falls es auch Wortzeichen besteht.

Schreibst du
%hash = ('test', 123, 'Perl', '5.28');
ist das nicht so ersichtlich was zusammen gehört.
Da kann sowas
%hash = (test => 123, Perl => '5.28');
viel praktischer sein.
Last edited: 2018-06-28 11:15:01 +0200 (CEST)

View full thread Subroutine als Parameter: Syntax Verständnisproblem