How does the perl switches "-E" and "-e" differ from each other? In this example they works exactly the same — executes the command after the switch:
$ perl -e 'print "$_\n" foreach 1..2'
1
2
$ perl -E 'print "$_\n" foreach 1..2'
1
2
The first one, -e , allows you to define Perl code to be executed by the compiler. For example, it's not necessary to write a “Hello World” program in Perl when you can just type this at the command line. $ perl -e 'print "Hello World\n"'
!~ Just like =~ except the return value is negated. x. The repetition operator. Returns a string consisting of the left operand repeated the number of times specified by the right operand.
This is explained in perldoc perlrun
:
-E commandline
behaves just like -e, except that it implicitly enables all optional features (in the main compilation unit). See feature.
The "See feature." refers to the documentation for the feature
pragma, which you can read by typing perldoc feature
.
-E
unlike -e
enables features
You can check what these are using Deparse
module (following is for perl 5.16),
perl -MO=Deparse -E 1
use feature 'current_sub', 'evalbytes', 'fc', 'say', 'state', 'switch', 'unicode_strings', 'unicode_eval';
From Perldoc:http://perldoc.perl.org/perlrun.html
•-e commandline :
may be used to enter one line of program. If -e is given, Perl will not look for a filename in the argument list. Multiple -e commands may be given to build up a multi-line script. Make sure to use semicolons where you would in a normal program.
•-E commandline :
behaves just like -e, except that it implicitly enables all optional features (in the main compilation unit). See feature.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With