2. Perl
Programming Environment
2.1 Brief History of Perl (Practical Extraction Report
Language)
2.2 Perl Applications for Now
2.3 Perl CGI Script Libraries
2.4 Perl Limitations
Helps for Improving the Slow Start Problem
2.5 Perl Programming Environment
Getting and Installing Perl
O'Relly's
Perl Home page
www.perl.com
Comprehensive
Perl Archive network (CPAN)
Activestates
Larry
Wall's Third "State of the Onion" Address
www.perl/com/pub/1999/08/onion/talk1.html
Perl for Windows Environment
Other New Features for Perl in the Windows Environment
Check if you have a Perl:
Perl.exe --
The Perl Interpreter in the 'bin" directory
C:\Perl\bin>perl -v
This is perl, version 5.005_03 built for MSWin32-x86-object
(with 1 registered patch, see perl -V for more detail)
Copyright 1987-1999, Larry Wall
Binary build 522 provided by ActiveState Tool Corp. http://www.ActiveState.com
Built 09:52:28 Nov 2 1999
Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5.0 source kit.
Complete documentation for Perl, including FAQ lists, should be found on
this system using `man perl' or `perldoc perl'. If you have access to the
Internet, point your browser at http://www.perl.com/, the Perl Home Page.
Editor for Creating Perl Programs
emac -- UNIX
vi -- UNIX
pico -- LINUX
edit -- Windows
notepad -- Windows
filename.pl -- The file extension for Perl program for associated
with the Perl Interpreter
CGI Scripts will be created directly on the UNIX or LINUX
server if you are using vi, emac, or pico editor for creating scripts.
If you use MAC or PC to write your scripts and the Web
server is at a remote location, you would need to do the following
2.6 Create
and Test Perl Programs
Create a
testing.pl script for Windows environment
1. Start
--> Programs --> Accessories --> Notepad
2. Enter
the three lines as shown below:
#!/usr/bin/perl -w
#testing.pl
print("My first Perl
Program\n");
print("Hello!\n");
3. Save
the file as "testing.pl" and place it in bin directory
4. Run
the testing.pl program
C:\Perl\bin>perl testing.pl
My first Perl Program
Hello!
5. For
UNIX environment
Change the
file into executable:
$chmod +x
testing.pl
Run the
program under the command line
$testing
Exercise
1. Use
Notepad to enter the following Perl statements
#printex.pl
print (1,2,3,4,5);
print "\n";
print (1..15);
print "\n";
print (a..z);
2. Save it
as printex.pl
3. Run the
program to verify the result
C:\ActivePerl522\bin>perl printex.pl
12345
123456789101112131415
abcdefghijklmnopqrstuvwxyz
Running
Perl for LINUX
· Login to LINUX machine: telnet 149.164.36.10
·
Check
the version of the Perl Interpreter
[plin@ecetlin plin]$ perl -v
This is perl, version 5.005_03 built for i386-linux
Copyright 1987-1999, Larry Wall
Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5.0 source kit.
Complete documentation for Perl, including FAQ lists, should be found on
this system using `man perl' or `perldoc perl'. If you have access to the
Internet, point your browser at http://www.perl.com/, the Perl Home Page.
·
Start
PICO editor; enter the first program as shown below; then save the program as
"test1.pl" by entering Ctrl W to write to a file and enter the file
name: pico test1.pl
·
Run
the program
[plin@ecetlin plin]$ perl test1.pl
My first Perl Program
Hello!
·
View
all files in the working directory using ls -al command
[plin@ecetlin plin]$ ls -al
total 56
drwx------ 3 plin plin 4096 Nov 15 14:33 .
drwxr-xr-x 28 root root 4096 Nov 13 15:01 ..
-rw------- 1 plin plin 447 Oct 2 10:41
.bash_history
-rw-r--r-- 1 plin plin 24 Sep 28 09:56 .bash_logout
-rw-r--r-- 1 plin plin 230 Sep 28 09:56 .bash_profile
-rw-r--r-- 1 plin plin 124 Sep 28 09:56 .bashrc
-rw-r--r-- 1 plin plin 3394 Sep 28 09:56 .screenrc
-rw-rw-r-- 1 plin plin 29 Sep 30 12:46 date.txt
drwxrwxr-x 2 plin plin 4096 Sep 30 13:10 localsite
-rw-rw-r-- 1 plin plin 27 Sep 30 12:50 names
-rw-rw-r-- 1 plin plin 746 Sep 30 13:06 pingfile.txt
-rw-rw-r-- 1 plin plin 27 Sep 30 12:59 reversenames
-rw-rw-r-- 1 plin plin 27 Sep 30 12:56 sortnames
-rw-rw-r-- 1 plin plin 85 Nov 15 14:33 test1.pl
[plin@ecetlin plin]$
·
Recognizing
file permissions
Three
levels of permissions associated with three classes of user groups:
User
(u) - the owner of the file or
directory. The owner's name can be seen
in
the display.
Group
(g) - the group that owns the
file.
Others
(o) - Any users
Three
levels of permissions:
r - Read the file or directory
w - Write the file or directory
x - Execute the file
·
Change
the file mode for "read", "write", and "execute"
Note
that you must have at least "read" and "execute" permission
to run a Perl program.
Add
execute permission for the owner (or user) of test1.pl
ls -l test1.pl
-rw-rw-r-- 1 plin plin 83 Nov 15 14:56 test1.pl
chmod u+x test1.pl
ls -l test1.pl
-rwxrw-r-- 1 plin plin 85 Nov 15 14:33 test1.pl
Add
permission for both the group and other classes
chmod go+rx test1.pl
ls -l test1.pl
-rwxr-xr-x 1 plin plin 85 Nov 15 14:33 test1.pl
2.7 LINUX/UNIX Security Mechanism
File security:
.Directory or regular file
.Owner read, write, execute
.Group read, write, execute
.Users read, write, execute
$chmod .... change
permissions
$chown .... change
ownership
$chgrp .... change
group
Password security: a password scheme prevents unauthorized users from
logging in.
$cat
/etc/passwd
-To change
password:
$passwd