Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable Perl features via command line?

Tags:

perl

I want to enable say feature (but also all the others). I know that if I write the code on the command line, I can use -E option instead of -e. But if I am running a script:

perl script.pl

I cannot use -E. I don't want to put use feature say in the script; I want to use command line option. What kind of option can I use here? I have not been able to figure this out from the documentation.

like image 873
Tomas Avatar asked Feb 01 '14 19:02

Tomas


2 Answers

You can import a module with the -M switch. In general,

-MFoo=bar,baz

is equivalent to

use Foo (split /,/ 'bar,baz');

So here, we would do -Mfeature=say or load a feature bundle like -M5.010.

However, I'd recommend specifying any features you use inside the script itself. This will avoid confusing errors when you forget to specify the switch.

like image 72
amon Avatar answered Oct 05 '22 23:10

amon


I made a bash alias:

alias sperl='perl -Mfeature=say'

now I can do stuff like

~/perl$ sperl -e "say 'hi'"
hi
like image 22
Steve O. Avatar answered Oct 06 '22 00:10

Steve O.