Jump to content

Perl Programming/Getting started

From Wikibooks, open books for an open world

This is an old revision of this page, as edited by 213.78.88.101 (discuss) at 20:52, 23 April 2004. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Getting Perl

Windows

www.activestate.com

Other OS'

www.perl.com

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.

Mac systems

Debugging programs

Packaging programs

Oneliners

Interactive mode