Tuesday, July 28, 2009

How do I compile a Perl file? (or is compiling not necessary?)?

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.

How do I compile a Perl file? (or is compiling not necessary?)?
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/activepe...





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/Ac... describes how to run your scripts under Windows.
Reply:/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.
Reply: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 %26lt;in.txt %26gt;out.txt








I hope that helps.
Reply: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
Reply: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.

love song lyrics

No comments:

Post a Comment