NAME
feature - Perl pragma to enable new syntactic features
SYNOPSIS
use feature qw(switch say);
given ($foo) {
when (1) { say "\$foo == 1" }
when ([2,3]) { say "\$foo == 2 || \$foo == 3" }
when (/^a[bc]d$/) { say "\$foo eq 'abd' || \$foo eq 'acd'" }
when ($_ > 100) { say "\$foo > 100" }
default { say "None of the above" }
}
DESCRIPTION
It is usually impossible to add new syntax to Perl without breaking some existing programs. This pragma provides a way to minimize that risk. New syntactic constructs can be enabled by use feature 'foo'
, and will be parsed only when the appropriate feature pragma is in scope.
The 'switch' feature
use feature 'switch'
tells the compiler to enable the Perl 6 given/when construct from here to the end of the enclosing BLOCK.
See "Switch statements" in perlsyn for details.
The '~~' feature
use feature '~~'
tells the compiler to enable the Perl 6 smart match ~~
operator from here to the end of the enclosing BLOCK.
See "Smart Matching in Detail" in perlsyn for details.
The 'say' feature
use feature 'say'
tells the compiler to enable the Perl 6 say
function from here to the end of the enclosing BLOCK.
See "say" in perlfunc for details.
the 'err' feature
use feature 'err'
tells the compiler to enable the err
operator from here to the end of the enclosing BLOCK.
err
is a low-precedence variant of the //
operator: see perlop
for details.
FEATURE BUNDLES
It's possible to load a whole slew of features in one go, using a feature bundle. The name of a feature bundle is prefixed with a colon, to distinguish it from an actual feature. At present, the only feature bundle is use feature ":5.10"
, which is equivalent to use feature qw(switch ~~ say err)
.