Question:
How do I compile a Perl file? (or is compiling not necessary?)?
Melzy
2007-07-07 03:27:42 UTC
For our report, we need to study Perl. I read a book on it and I was happy because the codes are short and easy to understand but WTF! It didn't say how to compile it. I downloaded something I thought as a Perl compiler but it didn't work. I tried searching the net but I was more confused because they're saying that the line "#!/usr/bin/perl" is already the compiler. Btw, i'm trying to make it work in the command prompt. I'm using Windows.
Six answers:
David D
2007-07-07 03:42:08 UTC
Perl is interpreted rather then compiled (Well, it isn't really, but it looks like it is, and its easiest to think of it like that for the time being).



You can get the Perl runtime for Windows from http://activestate.com/Products/activeperl/



On a UNIX or UNIX-like system (such as Linux or Mac OS X) you can usually find Perl at /usr/bin/perl on the file system (that would be akin to c:\Program Files\perl.exe on Windows), and the line you quoted is how the shell is informed that the program should be executed using perl. Windows works somewhat differently.



http://aspn.activestate.com/ASPN/docs/ActivePerl/5.8/readme.html#Using_ActivePerl describes how to run your scripts under Windows.
Dave H
2007-07-07 03:46:16 UTC
On unix systems (or linux systems) if the first two characters in the file are #!, then everything up to the end of the line is considered to be the program name and arguments to pass to the program to interpret the file.



for example if the program started with

#!/bin/csh



The program /bin/csh would be used as the interpreter of this file.



#!/usr/local/bin/perl



would cause perl to interpret this program.



#!/bin/false



would cause the /bin/false program to interpret (not run) this program.



Perl is an interpretive program. You don't need to compile it.



You just need to have the appropriate perl environment installed.



What makes the #! so interesting is that the languages that support this type of calling convention, also consider lines that begin with a # to be comments. This makes the program interpreted one way by the OS and another way by the executing program.



Windows does not have the convention that if the first 2 characters in the program file are #! then the rest of the line is the program to interpret the file.



You will need to create .bat files that perform the task such as a file called runit.bat that contain the following line



\perl\bin\perl runit.pl



Hope that helped.

dave@thehansens.com
anonymous
2007-07-07 03:47:12 UTC
Perl does not need to be compiled, although I believe it can be compiled which means a program will execute faster.



#!/usr/bin/perl



Tells the shell where to find the Perl executable program.



This is a Unix/Linux path so you'll have to change it for Windows.



You can get Linux free but you will have to install it on a separate partition.
teef_au
2007-07-07 03:40:15 UTC
/usr/bin/perl is the normal location of the PERL interpreter on a Linux System. In that context PERL is interpreted and can just be written as plain text and then run directly.



I have never dealt with PERL on a Windows System, only scripts on a Linux web server, which as I say are interpreted. I have since moved on to PHP and forgotten everything I learned about PERL sorry.
rt11guru
2007-07-07 03:55:03 UTC
I run perl scripts from the the DOS command prompt under Windows all the time.



My perl is installed in C:/perl with perl.exe in C:/perl/bin



To run a perl script, named script.prl with and input file of in.txt and output of out.txt the command is:



c:/perl/bin/perl.exe script.prl out.txt





I hope that helps.
anonymous
2016-10-20 08:02:15 UTC
The compiler (and the outputted byte code) is the comparable with the two. there will be no distinction in any respect between the compiled classes. NONE in any respect. The sixty 4 bit compiler itself will run particularly swifter on a sixty 4 bit device by using greater proper use of the registers. in spite of the incontrovertible fact that, it truly is in basic terms the overall performance of the compiler itself -- no longer the bytecode it produces, which -- returned -- would be precisely the comparable. So in case you do no longer care in the adventure that your application takes 3 seconds to collect as against 4 seconds to collect, then it truly does not count which one you employ.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...