| Previous: About Perl | Index | Next: Editors and IDEs |
This book assumes that you know absolutely nothing about programming at all and that Perl is your first language. However, basic operations such as making text files are outside of the realm of this tutorial.
To find out, if you already have Perl installed on your computer, go into the command line and type:
perl-v
This will display which version of Perl you have installed on your computer, if it is installed.
There are at least two easy ways to install Perl on Windows: theActiveState distribution, and theStrawberry Perl distribution. Both are downloadable as native Windows installers. ActivePerl has a prebuilt package repository and is supported by a corporation, while Strawberry Perl includes a compiler (gcc) so that perl modules can be installed "on the fly" and is community-supported.
Most Unix-like operating systems will include Perl by default, and Linux Standard Base mandates that all compliant Linuxes ship with Perl installed. However, if for some reason you don't have perl, you can explore the options available to you at themain Perl download page, which will provide links to source and binaries.
Perl is aninterpreted language, which means you will always need the Perl interpreter which willcompile andexecute your program each time you run it. Instead of compiling your program into bytecode, like inC++ orPascal, and then executing it, you can simply copy your program's source code to a different computer (that has the Perl interpreter) and run it.
For our first example, run your favorite text editor, and type something like this:
#!/usr/bin/perlusestrict;usewarnings;print"Hello World";
If you don't understand this yet, don't worry; This will be explained in more depth later.
Save the file asmyprog.pl and you have a Perl program ready to run.
To run a Perl program with a modern version ofActivePerl installed, you simply click on it. If the screen flashes and you can't see the output you might have to execute the file from within the windows shell (ie.cmd.exe or PowerShell). WithStrawberry Perl, you'll have to execute a Perl program from the command line as shown below.
From a Windows command-line interface, you can run the program thusly:
C:\> perl path\to\foo\myprog.pl
or, ifperl.exe is not in your path:
C:\> c:\perl\bin\perl.exe myprog.pl
Note: You may have to specify the full path to your program unless you are running the command prompt in that directory.
You can run a Perl program by running perl itself, and telling the shell the name of the file:
perl myprog.pl
Usually, Perl programs are made executable on their own. This involves two changes to the sample program. First, edit it and put the followingshebang line at the top of the file:
#!/usr/bin/perlThen, at a command prompt, make your program executable by usingchmod.
chmod+xmyprog.pl
Your program is now executable and ready to run, just like any other file. To execute, type:
./myprog.pl
By convention,.pl identifies a Perl script, and.pm a Perl library. The.pl file extension isn't needed for either of these examples; it's just a useful way of identifying files. The only time the conventionshould be violated is if the program is to be installed outside of the current working directory, and there runs a chance you might want to some day rewrite them in a different language.
| Previous: About Perl | Index | Next: Editors and IDEs |