Site hosted by Angelfire.com: Build your free website today!

Perl Programming

Tutorial Links:

ActiveState (d/l Perl for Windows and Tutorials)

Tutorial 1

Tutorial 2

Perl Scripting Tool


My Tutorials
These are scripts with remarks that explain whats going on. So you can read the remarks in notepad, then run them in Perl to see the output. Copy and paste the text in notepad and save it as name.pl or name.cgi Both file extentions are for Perl.

Arrays
File Handling
Functions
Writing HTML with Perl

Perl Scripts
Finger program
NT Scanner
IIS Unicode Exploit
Web Ping

Perl Basics
Assuming you have already downloded Perl from ActiveState if you'r running Win9x or NT, or have Perl running on your UNIX box, let's start,

I'm going to take this from the Windows view, so if you have UNIX and want to learn, sorry. Open up Windows Explorer and goto c:\perl. Make a new folder named script. This is where you are going to put your scripts. Open up notepad, this is what you will use to write code.

Now, open a DOS prompt. (Start, Programs, MS DOS Prompt) There is a nice little DOS program called DOSKey that remembers what you type in the command line. Type doskey and hit enter to install doskey. Now, if you have ActiveState Perl, cd to c:\perl\bin This is where the Perl.exe file is, it's the complier. Goto the notepad window. Put the following code in:

#!c:\perl\bin\
# This is a remark. When # is the first character on a line, the line is ignored by the compiler
# You can put stuff like the date, authors name, syntax and other info in the code with remarks.
$variable1="Hello";
print $variable1, "\n";

Ok, now save it in c:\perl\script as my.pl In notepad select save as all files, but it will save it as my.pl.txt, so in explorer, right click the file and rename. Delete the .txt and it will give you a message box, click ok and then it is my.pl. Goto the DOS prompt and type in perl c:\perl\script\my.pl and hit enter. This is how to run a Perl script. perl (path and filename). This is where doskey is handy. Say you run the script and it doesn't work right, you can modify it in notepad and save it again as the same filename. At the dos prompt, you don't need to type in the syntax again, just press the up arrow key and the last command you typed will show up, which was perl c:\perl\script\my.pl so just hit enter to run it again.

So you ran my.pl and it printed Hello. Now here's what happened in the program. Line 1 #!c:\perl\bin\ is the path to perl.exe. This path is a UNIX path. It's used if you have a website and they provide CGI. Write the path of perl on the first line like this: #!path If you want to use Perl scripts on your webpage, check with your provider to see if Perl is available and what the path is.

The remarks are understood, right? $variable1="Hello"; This is how to use variables in Perl. $varname is declaring a string variable. varname is the variable name. No spaces allowed, and some symbols, just keep it simple. The data types are the same as QBASIC, but in Perl it's $varname, in QB it's varname$. So that line you declared $variable1 equal to the string Hello.

print $variable1, "\n"; This is the print statement. You can print a variable or print a string like this. print "Hello ", $name, "\n"; This would print the word Hello a space and the value of $name. Now lets get to the "\n" at the end. This begins a new line.

One thing to remember: All lines in Perl end with a semi-colon (;), Except for things like an if statement. Download some scripts and read them to understand. If you mess up and run a Perl script it will erase all the files on your hard drive and blow up your monitor. j/k, the compiler will tell you whats wrong.




Navic's Home
DuckTape's Home