Why Perl don't have pragma like -E option?
Perl one-liner have -E option. This enable latest perl version.
perl -E "say 'Hello'"
but perl don't have pragma like -E option.
I don't like syntax like use v5.18.
I want to write the following way.
use latest;
and controll current perl version by environment variable. For example,
export PERL_LATEST_PRAGMA=v5.18
'latest' is already occupied:
https://metacpan.org/module/latest
How about creating and releasing that module yourself? It's doable with a couple of lines. You'll need to decide what to do with tainting.
In the mean time, how about just (this acts globally though):
PERL5OPT=-Mv5.16
Hi,
Although you may not like the default syntax (would love to know why...) I don't think its a bad approach and its not particularly verbose. I'd hesitate to write a module to do the same thing but a totally different way. Think about the people that come after you, maintaining your code. It increases the local specific knowledge needed to understand it, increasing complexity and possibility of errors for what seems to me to be dubious value.
I know, Perl and "There's more than one way to do it", etc. but sometimes its better to stay within strong community practices unless there's a really great reason otherwise. Just my thinking. --john
The pragmata
use v5.12
,use v5.14
, etc have well-defined meaning which won't change (much) in future versions of Perl.use v5.18
means "enable the features of Perl 5.18" today, and will mean the same thing in five years from now.A theoretical
use E
might mean "enable the features of Perl 5.18" today, but "enable the features of Perl 5.28" in five years' time. I'd hope that Perl 5.28's syntax isn't completely incompatible with Perl 5.18's, but some differences are probably likely. (There must be some people out there with functions calledfc
that are run fine under Perl 5.16+, but break under an explicituse v5.16
pragma.)For a throwaway one-liner
-E
is fine. I don't care that it will mean something different in five years. I don't care if it means something different tomorrow. I only care what it means today.For a script you're going to keep, a pragma that acts like a moving target is less desirable. Something like
use E
might save you two seconds of typing today but cause you annoyance a few years down the line.(For this reason I'd also argue against using
-E
in one liners that you're saving as shell aliases in your shell's "rc" file, or any other place that Perl one-liners might be long-lived.)Why don't you like the syntax? Is there a technical reason (and there are plenty of those) or something else?
I gave up having feelings about established syntax.
Because you can only say “give me all the features of version X.Y”, future perls that have more features can limit themselves to giving your code only the features that existed when you wrote it. That means even if such perls have features that would break your code, your code will still work, because it did not ask for them. So there is no problem if these perls contain incompatible new features.
But if you could write a line to tell Perl “give me all your features, no matter what version you are”, then every feature added to Perl from now until eternity would have to be done very carefully to try to avoid breaking your code. Even though these features did not exist when you wrote your code, your code will still ask for them if it runs on a newer perl than it was written on, so they all have to be made compatible.
The absence of this syntax, then, is by design. You are made to endure this very tiny inconvenience on purpose: for the good of Perl. It is not an oversight.
Extending Aristotle's points, the reason that some modules, like Mojo::Base can import the v5.10 features into the caller is because they themselves require 5.10.
Remember, what you are doing is specifying a minimal compatible version and for doing so you get the compatible syntax and features. Scripts should ask for what they need, not ask for everything, to be future proof and past resistant.
Name "latest" is example name. I write hope that i want to use latest feature more easily.
I think that theare two type people. one is conservative ,other is people who like new thing.
I don't know what is perl benefit. But maybe, there are people who use perl new features, strict, wranings, utf8 more easily.
Accusation to perl compared with python and ruby is that perl don't have good default.
use strict;
use warnings;
use utf8;
use feature 'default';
To write these in all scripts is boring work.
If syntax is not easy, people don't tend to write these.
I think writing version in script is not convenient, becuase if perl version is up, we rewrite it.
I don't deny "use v5.16" syntax. I hope pragma that latest perl feature(contains strict, warnings, utf8) is enabled.
There are two people. One want strong compatibility. Other don't want strong compatibility and want good default.
Module author want strong compatibility, but Application author, for example, who provide web site don't want strong compatibility and tend to want good default.
There are two people. One want strong compatibility. Other don't want strong compatibility and want good default.
syntax "use v5.16" satisfy former demand, but don't satisfy latter demand.
Why?
If your script says "v5.18" and someday perl 5.20 is released, why do you have to rewrite "v5.20"? For testing? Your "v5.18" line and the script will still work if run by perl 5.20.
>If your script says "v5.18" and someday perl 5.20 is released, why do you have to rewrite "v5.20"? For testing? Your "v5.18" line and the script will still work if run by perl 5.20.
the script work well, but we usually want to rewrite "use v5.18" to "use v5.20" in Perl 5.20.
What I want to say is that there are some users who don't think about version number and use latest feature easily.
Except those who claim they don't care for "compatibility" will complain loudly when the next Perl (the latest) they install breaks their code. Even though they claimed they didn't care.
And speaking of good defaults, "continues to work as expected" is a very good default. And that's what Perl gives us.
Your assumptions is that only new features are added in newer versions. This is wrong. Features may also be removed or changed in incompatible (or subtile incompatible) ways and that can break existing code.
Perl is quite good at maintaining backward compatibility. You seem to want that Perl becomes as broken as Python or Ruby on that matter.