Available Guides:::::
Perl Guide by ryza
this guide is intended for perl and wisdom seekers.
print qq~
1. what is perl.
2. a basic perl script.
3. perl in your terminal.
4. running a perl script (browser).
~;
section #1
Perl is the brainchild of Larry Wall.
He continues to develop and maintain the language, which, through the
help of the net.community, is available on virtually every computer platform,
from Apple Macintosh to VMS.
Perl is an acronym for "Practical Extraction and Report Language", although
you'll sometimes hear it referred to as the "Pathologically Eclectic
Rubbish Lister." It started out as a scripting language to supplement
rn, the ubiquitous USENET reader, which Wall also wrote.
(Most people could only dream of writing a program that is installed on every
UNIX box on the planet - Larry has two.)
It is an interpreted language that is optimized for string
manipulation, I/O, and system tasks. It has builtins for almost
everything that's in section 2 of the UNIX manuals, which makes
it very popular with system administrators. It incorporates
syntax elements from the Bourne shell, csh, awk, sed, grep, and C.
Perl has gained recent attention in the explosion of the World Wide
Web as a quick and effective way to mock up applications that provide
much of the web's interactivity. It has a lot of syntax that can make
scripts contain more characters from the top row of the keyboard than
any other, but that is not necessary to get anything done. In fact,
there are few of the traditional limitations that interpreted
section #2
line 1: #!/usr/bin/perl
line 2:
line 3: print "Content-Type: text/html\n\n";
line 4:
line 5: print "Hello World!!";
line 1: this line is used to define the path to the perl executable on the server, the default install path for this program on a linux machine is /usr/bin/perl however it could be located anywhere. /usr/local/perl etc. so before your program will run you need to have the correct path to (Perl) on the first line of any perl script/program.
line 2: your script dosnt require spaces inbetween lines, i used gaps to make it easy to read'.
line 3: this is the Content-Type (aka header). you cannot (print!) to a page without telling it what your trying to print. i am printing text to the screen on "line 5" so the content type here is text/html. your script wont run without this.
line 4: your script dosnt require spaces inbetween lines, i used gaps to make it easy to read'.
line 5: to print anything to the screen it must be defined in a print tag.
section #3
to use these examples im assuming you have perl installed :)
open your terminal and type the following line
perl -e 'print "Hello World!!\n";'
this prints the text 'Hello World' to the screen.
or if you wanted to find out your perl version you could type:
perl -e 'print "perl version is: $]\n";'
this prints the text 'perl version is: 'your perl version'' to the screen.
here is a more advanced example of code.
perl -e '$max=100000; $current=50000; $n=1; while($n < $max){ if($n eq $current){exit;} else{$n++; print "$n\n";} }'
this forces the program to exit; half way through its process of counting
to 100000 and printing 1-50000 to the screen. this is a good example of writing code.
you could say 100000 is the maximum of something you want to print & 50000 is the current value of what u actually have.
there is better ways to do things like this but for this guide im not going into details on how to make your code more efficient ;)
here is what u get
1
2
3
4
5
6
7
8
9
10
all the way to 50000 (it goes fast)
section #4
first you need to upload/put the file with the perl code into a CGI Enabled directory. (name it: test.pl)
if your running apache and testing it on your linux machine locally and not on a webhost u might need to open the apache config file and define a directory for cgi scripts to run in. the apache config is usually located here. /etc/httpd/conf/httpd.conf
apache usually has a default cgi-bin setup "/var/www/cgi-bin" something like that.
now that you have your file all setup in a cgi-bin you need to give it some permissions to be able to run/execute. (chmod)
so you want to chmod your perl file to 755. if your doing it from bash just type "chmod 0755 /var/www/cgi-bin/test.pl"
now that you have your perl file in a cgi-bin and have given it some permissions, try going to the file from your browser,
http://localhost/cgi-bin/test.pl or if you have it on a webhost: http://somefreeserver.com/user/cgi-bin/test.pl
Other Related Sites:
the monastery gates
perldoc.com
www.perl.org
cgi-resources.com
hotscripts.com
Suggest a link?:
mail us
|