Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

run perl -e from inside perl script in windows

Tags:

windows

perl

I need to run the following command from inside a Perl script in Windows. The code can't be simpler than this:

#! C:\Perl\bin\perl

perl -e "print qq(Hello)";

I save this file as test.pl. I open a command prompt in Windows and run the following from the c:\Per\bin directory. When I run it as perl test.pl, I get the following result:

C:\Perl\bin>perl test.pl
syntax error at test.pl line 3, near ""perl -e "print"
Execution of test.pl aborted due to compilation errors.

How can I fix this? If I just run perl -e from the command prompt (i.e. without being inside the file) it works great.

like image 566
user421787 Avatar asked Apr 20 '26 04:04

user421787


2 Answers

The test.pl file should contain:

print qq(Hello);
like image 175
codaddict Avatar answered Apr 21 '26 17:04

codaddict


Why would you want to run perl code with perl -e …? Just put the actual code in your program.

If, on the other hand, you want to run an external command from within your program, then the answer depends on what you want to do with the input/output and/or the exit code of your program. Have a look at system, qx and open.

like image 24
pavel Avatar answered Apr 21 '26 19:04

pavel