In this answer is used the perl one-liner as:
perl -we \'... CORE::say \"x=$x\"\'
What is the advantage using the -e
and
feature.pm was introduced to allow backwards-incompatible features to be added to Perl. -E
enables all backward-incompatible features, which means a program that uses -E
may break if you upgrade perl
.
perl -E'... say "foo"; ...' # Forward-incompatible (5.10+)
perl -Mfeature=say -e'... say "foo"; ...' # ok (5.10+)
perl -Mv5.10 -e'... say "foo"; ...' # ok (5.10+)
perl -M5.010 -e'... say "foo"; ...' # ok (5.10+)
perl -e'... CORE::say "foo"; ...' # ok (5.16+)
For example, say you wrote the following program in 2010:
perl -E'sub fc { my $acc=1; $acc*=$_ for 2..$_[0]; $acc } say fc(5);'
With the latest Perl in 2010 (5.12), the program outputs the following:
120
With the latest Perl in 2016 (5.24), the program outputs the following:
5
The difference is due to the addition of a feature to 5.16 that changes the meaning of that program when enabled. If one had avoided the use of -E
, the program's behaviour would not have changed. Specifically, the following outputs 120
in 5.24:
perl -e'sub fc { my $acc=1; $acc*=$_ for 2..$_[0]; $acc } CORE::say fc(5);'