|
|
|
Perl
Basics
Starting Perl
Typically, perl is used to interpret a script. You can run a
script explicitly with perl (the % is your command prompt)
% perl scriptname
or
% cat scriptname | perl
That isn't convenient enough, since you'd rather not have to
distinguish what is a real compiled program and what is a
script. Therefore, UNIX shells have a shortcut. If a text file
is executable, and the first line is of the form
#!program [optional program arguments]
the shell executes
program [optional program arguments] scriptname
Note: While there is some leading whitespace to offset the
code examples, all examples should not use the first
- especially this example of the shell shortcut.
--------------------------------------------------------------------------------
Example
To start off our program, edit the file mailform, add the
first line:
#!/usr/local/bin/perl
(or whatever the location of your perl binary is), save, exit
the editor, and make the program executable:
% chmod +x mailform
___________________________________________
Here's some information that applies to all of perl.
Perl is free form - whitespace doesn't matter. Most people
like to use liberal indentation, but you could write all on
one line, if you're a masochist.
All perl statements end in a ; (semicolon), like C.
Comments
begin with # (pound sign)
everything after the #, and up to the end of the line is
ignored.
the # needn't be at the beginning of the line.
There is no way to comment out blocks of code other than
putting a # at the beginning of each line. It's a convention
taken from the shell utilities, sorry C folks.{damn}
--------------------------------------------------------------------------------
Example
Now our program looks like this:
#!/usr/local/bin/perl
# mailform - a simple CGI program to email the contents of an
HTML
# form to a specified user.
#
# kolij badman
# kolij@osr.nitto
# September, 2003
-kolij-
|
|