Perl Programming/Getting started
Getting Perl
Windows
Other OS'
Writing programs
Perl programs are simple text files -- run your favourite text editor, and type something like this:
# This is a perl program print "This is a perl program", "\n";
Save the file as "myscript.pl", and you have a perl program ready to run.
Running programs
Windows
To run a perl script with ActivePerl installed, you can right-click on it, and "open with" c:\perl\bin\perl.exe (this may already be setup and labelled as "perl command line interpreter")
It's possible to put a shortcut to perl.exe in the "SendTo" menu, so that any file can be run as a perl-script by right-clicking on it, and selecting "send to", "perl".
From a windows command-line, the program can be run thusly:
c:\perl\bin\perl.exe myscript.pl
or, if perl.exe is in your path:
perl myscript.pl
One other method is to make a batch file, containing something like:
@c:\perl\bin\perl myscript.pl @pause
Using a batch file allows you to see the program output without the window disappearing as soon as the program finishes.
UNIX-like systems
To run a perl script, just type it like thus: (where myscript.pl is the name of your program)
/usr/bin/perl myscript.pl
Alternatively, you can make your program into an executable file. Make sure the first line of your program contains the following text:
#!/usr/bin/perl
Then, at a command prompt, make your script executable
chmod a+x myscript.pl
Your program is now ready to run, just like any other executable file. To run it, type:
./myscript.pl
The .pl file extension isn't needed for either of these examples, it's just a useful way of identifying files.