Search code examples
perlpragma

Why does the pragma order matter when enabling experimental features?


Is it the defined behavior that the order of features and use version matters?

use feature 'signatures';
use v5.026;

vs

use v5.026;
use feature 'signatures';

The top will produce an error,

Global symbol requires explicit package name

on

use feature 'signatures';                                                                                        
use v5.026;                                                                                                      

sub foo ($opt1, $opt2 = undef) {                                                                                 
  say $opt1 if $opt2;                                                                                            
}

Solution

  • The use v5.026 declaration implicitly enables the feature bundle for that version, in this case it would be equivalent to no feature ':all'; use feature ':5.26'. This overrides the features you had enabled/disabled already.