Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between uppercase "-E" switch and lowercase "-e" in perl?

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
like image 667
bessarabov Avatar asked Oct 14 '13 05:10

bessarabov


People also ask

What is Perl E?

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"'

What does !~ Mean in Perl?

!~ 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.


3 Answers

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.

like image 109
Keith Thompson Avatar answered Oct 23 '22 18:10

Keith Thompson


-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';
like image 22
mpapec Avatar answered Oct 23 '22 20:10

mpapec


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.

like image 34
Nikhil Jain Avatar answered Oct 23 '22 19:10

Nikhil Jain