-, :
( ..), ?
Autodeclare
strict "pragma" , , P6, /, sigil, .
P6 . , , / , my. , , P6 , /.
use strict no strict, :
no strict;
say $text;
BEGIN {
$text = "abc";
}
no strict , use strict .
,
. :
say my $text;
BEGIN {
$text = "abc";
}
my $bar , . , say my $bar = 42; if foo { say my $bar = 99 } $bar .
BEGIN .
/ , INIT:
say my $text;
INIT {
$text = "abc";
}
A PS ?
, - Perl 6 () / Rakudo (), - "". ( P6/Rakudo , - P6, P6 MOP, P6 pragmas.)
, - - :
use PS;
say $text;
BEGIN $text = 'abc';
$text mainline , no strict. PS , / , / , ( ).
say foo;
sub foo { 'abc' }
, , .
(More precisely, when the P6 compiler encounters an identifier without sigil while parsing some source code, it checks if it has already seen the declaration of this identifier. If it does not matter, then it assumes that the identifier corresponds to the procedure that will be announced later and will be move on. If his assumption is wrong, it will not compile.)
You can use routines as if they were variables, as described in Christopher Bott's Answer .