Unix
We will be working with Perl on the ITP Stage server, which runs the operating
system Linux. Linux is a version of Unix - and you interact with it through
the command line. Very geeky. So you need to know some basic commands:
Unix commands
cd - change directory
mkdir - make directory
ls - shows all files in current directory
ls -l - shows all files with permission information
cd .. - takes you up a directory
pwd - print working directory
chmod - changes permissions
mv - moves a file
cp - copies a file
rm - removes a file
For more on unix, take a look at this Unix Tutorial for Beginners
Getting Started Step-by-step
1. Telnet into stage.itp.tsoa.nyu.edu
So you need a telnet program. Mac OSX you can use the terminal.
You can go to tucows.com to download Putty for Pc or Nifty Telnet for Mac.
2. Enter userid and password (same as NYU mail account)
3. Go into your public_html folder by typing cd public_html
4. Create a folder called cgi by typing mkdir cgi
5. Go into the new cgi folder by typing cd cgi
6. Open a new file called program1.cgi in pico (word processing program on server) by typing pico program1.cgi
7. Type the following:
#!/usr/local/bin/perl
print "hello world!\n";
8. Exit out of pico with Control-X
9. Make your program executable by typing chmod a+x program1.cgi
10. Run your program by typing program1.cgi
11. Congratulations! You have written and executed your first perl program.
Pico
Pico is an easy to use (relatively speaking) word processing program
on the server. It is the same program used by Pine mail. If you end up
doing lots of perl programming, it's probably worthwhile to learn another,
more powerful unix text editor, like vi or emacs. Much more complicated,
but much more powerful. Pico will suit our purposes just fine.
Use arrows to move around. Delete on the keyboard should work.
Control-x to save and exit.
Control-g to get help.
Perl Basics
Ok - A Bit About Perl
1. All perl programs need to start with
#!/usr/local/bin/perl
This tells the server where to find the perl interpreter.
2. Use # to comment
3. All lines of a Perl program must end with ;
4. Variables start with $
5. Lists start with @
6. To print a new line, use \n
7. To get input from command line, use <STDIN>
Great resource: Free online book Learning Perl
Perl vs. Director: A little bit of compare and contrast
Perl | Director |
Server-side | Client-side (though it can communicate with server - next week) |
text-based (though you can point to multi-media elements from browser) | more inherently multi-media |
user interaction only through text (unless you are using web elements) | user interaction from mouse events, key down, text fields, etc. |
Is a programming language with somewhat intimidating syntax | Has a built-in scripting language, Lingo |
To comment: use # | To comment: use -- |
if ($seventh eq "on") { print "You want to know\n"; } else { print "Oh well, you don't want to know\n"; } |
if seventh = on then put "You want to know" else put "Oh well, you don't want to know" end if |
for ($i = 1; $i <= 5; $i++) { print "$i "; } |
repeat with i = 1 to 5 put i end repeat |
@myarray = (a, b, c, d, e); foreach $letter (@myarray) { print "$letter\n"; } |
mylist = ["a", "b", "c", "d", "e"] repeat with i = 1 to mylist.count put mylist[i] end repeat |