'result'
è l'ultima istruzione del blocco { say "2 seconds are over!"; 'result' }
. Nelle lingue Perl, i punti e virgola (non le nuove righe) determinano le estremità della maggior parte delle istruzioni.
In questo codice:
my $timer = Promise.in(2);
my $after = $timer.then({ say "2 seconds are over!"; 'result' }); # 'result' is what the block returns
say $after.result; # 2 seconds are over (printed by the say statement)
# result ('result' of the block that is stored in $after)
La seconda linea potrebbe essere riscritto così:
my $after = $timer.then({
say "2 seconds are over!";
'result'
}
); # 'result' is what the block returns
Tale e virgola termina semplicemente l'istruzione say "2 seconds are over!"
.
Al di fuori di un blocco, questa linea
say "2 seconds are over!"; 'result';
è davvero due affermazioni:
say "2 seconds are over!"; # normal statement
'result'; # useless statement in this context (hence the warning)
Mettere più istruzioni in una sola riga cambia raramente come si comportano:
my $timer = Promise.in(2); my $after = $timer.then({ say "2 seconds are over!"; 'result' }); say $after.result; # Still behaves the same as the original code. ... Do not edit. This is intentionally crammed into one line!
fonte
2016-01-27 00:32:31
Il ' {...} 'è un blocco nuda, simile a una subroutine. –
Grazie ora ha senso per me – smith