I was going to suggest something along the lines of BEGIN { eval "use $]; 1" or die $@ } instead (Bug in eval in pre-5.14), but it doesn't actually work to enable features:
$ perl -e 'BEGIN { eval "use $]; 1" or die $@ } say "foo"'
String found where operator expected at -e line 1, near "say "foo""
(Do you need to predeclare say?)
syntax error at -e line 1, near "say "foo""
Execution of -e aborted due to compilation errors.
Because the scope of feature is limited to the lexical scope.
So, Anonymous Monk, to echo stevieb: Why do you (think you) need this? (Why try to do something dynamically that is determined statically / at compile time?) |