1experimental(3) User Contributed Perl Documentation experimental(3)
2
3
4
6 experimental - Experimental features made easy
7
9 version 0.021
10
12 use experimental 'lexical_subs', 'smartmatch';
13 my sub foo { $_[0] ~~ 1 }
14
16 This pragma provides an easy and convenient way to enable or disable
17 experimental features.
18
19 Every version of perl has some number of features present but
20 considered "experimental." For much of the life of Perl 5, this was
21 only a designation found in the documentation. Starting in Perl
22 v5.10.0, and more aggressively in v5.18.0, experimental features were
23 placed behind pragmata used to enable the feature and disable
24 associated warnings.
25
26 The "experimental" pragma exists to combine the required incantations
27 into a single interface stable across releases of perl. For every
28 experimental feature, this should enable the feature and silence
29 warnings for the enclosing lexical scope:
30
31 use experimental 'feature-name';
32
33 To disable the feature and, if applicable, re-enable any warnings, use:
34
35 no experimental 'feature-name';
36
37 The supported features, documented further below, are:
38
39 · "array_base" - allow the use of $[ to change the starting index of
40 @array.
41
42 This is supported on all versions of perl.
43
44 · "autoderef" - allow push, each, keys, and other built-ins on
45 references.
46
47 This was added in perl 5.14.0 and removed in perl 5.23.1.
48
49 · "bitwise" - allow the new stringwise bit operators
50
51 This was added in perl 5.22.0.
52
53 · "const_attr" - allow the :const attribute on subs
54
55 This was added in perl 5.22.0.
56
57 · "declared_refs" - enables aliasing via assignment to references
58
59 This was added in perl 5.26.0.
60
61 · "isa" - allow the use of the "isa" infix operator
62
63 This was added in perl 5.32.0.
64
65 · "lexical_topic" - allow the use of lexical $_ via "my $_".
66
67 This was added in perl 5.10.0 and removed in perl 5.23.4.
68
69 · "lexical_subs" - allow the use of lexical subroutines.
70
71 This was added in 5.18.0.
72
73 · "postderef" - allow the use of postfix dereferencing expressions
74
75 This was added in perl 5.20.0, and became non-experimental (and
76 always enabled) in 5.24.0.
77
78 · "postderef_qq" - allow the use of postfix dereferencing expressions
79 inside interpolating strings
80
81 This was added in perl 5.20.0, and became non-experimental (and
82 always enabled) in 5.24.0.
83
84 · "re_strict" - enables strict mode in regular expressions
85
86 This was added in perl 5.22.0.
87
88 · "refaliasing" - allow aliasing via "\$x = \$y"
89
90 This was added in perl 5.22.0.
91
92 · "regex_sets" - allow extended bracketed character classes in
93 regexps
94
95 This was added in perl 5.18.0.
96
97 · "signatures" - allow subroutine signatures (for named arguments)
98
99 This was added in perl 5.20.0.
100
101 · "smartmatch" - allow the use of "~~"
102
103 This was added in perl 5.10.0, but it should be noted there are
104 significant incompatibilities between 5.10.0 and 5.10.1.
105
106 · "switch" - allow the use of "~~", given, and when
107
108 This was added in perl 5.10.0.
109
110 · "win32_perlio" - allows the use of the :win32 IO layer.
111
112 This was added on perl 5.22.0.
113
114 Ordering matters
115 Using this pragma to 'enable an experimental feature' is another way of
116 saying that this pragma will disable the warnings which would result
117 from using that feature. Therefore, the order in which pragmas are
118 applied is important. In particular, you probably want to enable
119 experimental features after you enable warnings:
120
121 use warnings;
122 use experimental 'smartmatch';
123
124 You also need to take care with modules that enable warnings for you.
125 A common example being Moose. In this example, warnings for the
126 'smartmatch' feature are first turned on by the warnings pragma, off by
127 the experimental pragma and back on again by the Moose module (fix is
128 to switch the last two lines):
129
130 use warnings;
131 use experimental 'smartmatch';
132 use Moose;
133
134 Disclaimer
135 Because of the nature of the features it enables, forward compatibility
136 can not be guaranteed in any way.
137
139 perlexperiment contains more information about experimental features.
140
142 Leon Timmermans <leont@cpan.org>
143
145 This software is copyright (c) 2013 by Leon Timmermans.
146
147 This is free software; you can redistribute it and/or modify it under
148 the same terms as the Perl 5 programming language system itself.
149
150
151
152perl v5.30.1 2020-02-24 experimental(3)