Você está na página 1de 9

PRACTICAL EXTRACTION AND REPORT LANGUAGE

INTERNET PROGRAMMING LANGUAGES:-


Internet programming was given a boost with the advent of WWW to satisfy the
demand for Internet based applications which grew manifold. These applications requires a
language for their development.These languages were require to provide dynamic and an
interactive content to static web pages.The client /server model was the obvious choice for
internet applications.
In client server model the client sends request to the server ,the server does't have the
capability to process the cllient requests.So, it internally contacts CGI to process the client
request. The CGI process the client request and sends the response back to server. Now , the
server sends the response to the client in the forn of HTML page.

INTRODUCTION TO CGI:-

The common gateway Interface(C.G.I) is a specification defined by the world wide web
consortium, definining how a program interacts with a Hyper Text Transfer Protocal(HTTP)
server. The CGI provides middleware between www servers and external databases and
information sources.
WHY IS CGI USED:-

The interactive web pages, thet display some present information. These interactive web
pages enable a client to send information to the web server and get back a response that depends
on the input.
To create an interactive web page, HTML elements are used to display a form that
accepts a client's input and passes this to special computer programs on the web server. These
computer programs process a client's input and return requested information. These programs
are known as gateways because they typically act as a conduit between the web server and an
external source of information such as database.

COMMON USES OF CGI:-

==>Gathering user feedback about a product line through an HTML form.


==>Querying an oracle database and rendring the result as an HTML
SSdocument.

PROCESS OF CGI:-
==>A client makes an HTTP request by means of a URL. This URL could be
typed into the 'location' window of a browser.
==>From the URL, the web server determines that it should active the gateway
program listed in the URL.
==>The gateway program process the information and returns HTML text to
the web server. Then it returns HTML text to web browser.
==>The web browser displays the document received from the web server.

HOW INFORMATION IS TRANSFERRED FROM THE WEB BROWSER TO A CGI


PROGRAM:-
The web browser uses the method attribute of the <form> tag to determine how send
the form's data to the web server. There are two submission methods: GET and POST.
GET=>>The web browser submits the form's data as a part of a URL. The GET
command sends a URL to the web servber. If the form's data is sent to the web
server using the GET command, the browser must include all data in the URL.

POST=>>The web browser sends the form's data separately from the URL as a
stream of bits. In the POST method, the web browser sends the POST command to
the server and includes the form's data in the body of that command. The POST
method can handle any amount of data.

WHY PERL FOR CGI? :-


A CGI program can be written in any language like c, c++, vb
script, perl, TCL, REXX, python, Icon, Applescript,Unix shell scripting. But PERL is especially
suited for this because perl programs are easy to learn and write. PERL is a scripting language,
which means it does not have to be compiled. Instead, an interpreter executes the perl script,this
makes it easy to write and test PERL scripts, because they do not have to go through the typical
edit-compile-link cycles.

PERL
HISTORY OF PERL
Developed by "Larry Wall" basically on UNIX systems. The basic reason for developing
PERL is it gives much flexibility in string manipulations. PERL is an acronym for "Practical
Extraction and Reporting Language". It was originally created to extract information from text
files and then use that information to prepare breports.
Perl has gained recent attention in the explosion of the W.W.W 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 or the keyboard then any other,
but that is not necessary to get anything done. In fact there are few of the traditional limitations
that interpreted language impose.

FEATURES OF PERL:--

--->PERL is case sensitive language.


--->PERL is freeform language.
--->Each PERL statement must end with a semicolon(;).
--->Comments begin with hash mark(#).
--->A group of PERL statements can be treated as a block by enclosing them
in braces({......}).
--->It is interpreted based language.
--->It is a scripting language.
--->String manipulations are very easy.
--->Code optimisation.

STRATEGY:-
Strategy for this seminar is to establish the basics of perl. The script we'll be useful to
anyone who has wanted to create some interactive pages on the world wide web. Web servers
usually support running auxiliary programs to facilitate interactive content.There is standard
called C.G.I which defines a minimum set of environment variables that the program can use to
determine its response.
The program we write will take the results of an HTML form and mail the values to a
specified person. Writing the HTML for this form is beyond the scope of this seninar, but a
sample form be provided.
The beauty of this program is that any user on the web server can use it to response to their
forms. You don't need to give everyone access to your server configuration. Users will enbable
themselves for this program, and then can write arbitrary forms from anyone on the web to fill
out.

VARIABLES:-
Variables are used to store data. In PERL each variable has a name and can store any
type of data. Each variable name in PERL begins with special character. There are five special
characters are used in PERL.

* a dollar($) sign
* an at(@) sign
* a percent(%) sign
* a amphercent(&) sign
* a lessthan greaterthan(<>) symbol

Special character denotes the variable type. There are five types of variables availible in
PERL language.
* Scalar variables
* Indexed Array variables
* Associative Aray variables
* subroutine
* file handler

In PERL, there is no data type for a variable. The sex or datatypr of the variable is
dependent on the context in which it is used.

SCALAR VARIABLES:-

A scalar variable can reference a string value or a numeric. We can identify these two by
visible difference. If the value of the variable is surrounded in single of double quotes, then PERL
treats the variable as a string. If there are no quotes, then PERL has to decide if the value is a
string or a numeric value. These variables are preceded by the '$' sign.

$firstname="sanjay";
$lastname="kumar";
$age=23;

INDEXED ARRAY VARIABLES:-

These arrays are indexed by only integer values. Indexed arrays are denoted by the '@'
sign.

Ex:-@months=("jan","feb","mar","apr","may","jun");
Arrays are start at index 0. In the above example @months[0] will have a value jan and
@months[1] have feb.
Extracting Information from an Indexed Array:-
The 'qw' keyword is a ahortened form used to extract individual words from a string. The
most common method of extracting information from an array is to index the array elements
directly.
Ex:-@months=qw(jan feb mar apr may jun);
for($x=0;$x<=$#months;$x++)
{
print "index[$x]=$months[$x] \n";
}

ASSOCIATIVE ARRAY VARIABLES:-

These arrays are also called 'Hash' arrays. They are indexed by string values instead of by
integer index values. These arrays are identified by '%' sign.
Ex:-%cities=("a","hyderabad","b","bangalore","c","chennai");
The above example can be rewritten as:-
$cities{'a'}=hyderabad;
$cities{'b'}=bangalore;
$cities{'c'}=chennai;

Extracting Informatioin from an Associative array:-


The contents of an associative array can be accessed using three PERL functions. They
are: keys, values, each.
'keys' function:-
The keys function returns a list of the keys of the given associative array.
Ex:-#!g:\perl\bin\perl
%cities=("a","hyderabad","b","bangalore',"c","chennai");
for $key(keys%cities)
{
print "key=$key \n";
}
'values' function:-
The values function can be used to directly access the values in an associative array.
Ex:-#!g:\perl\bin\perl
%cities=("a","hyderabad","b","bangalore");
for $value(values %cities)
{
print "value=$value \n";
}
'each' function:-
The each function returns a key-values pair from thje associative array.
Ex:-#!g:\perl\bin\perl
%cities=("a","hyderabad","b","bangalore");
while(($key,$value)=each%cities)
{
print "key=$key value=$value \n";
}

ARITHMATIC&RELATIONAL OPERATORS:-

=>>Arithmatic operators are same as in the C language.


=>>In some languages, relational operators are used to comparing numbersb and also
for text strings. But,PERL has a complete set of relational operators for comparing
strings.

Operator Example Description


eq $x eq $y value is true if the strings $x and $y are
equal,else false.
ne $x ne $y value is true if the strings $x and $y are
not equal ,else false.
gt $x gt $y value is true if $x is greater than $y,else false.
ge $x ge $y value is true if $x is greater than or equal to
$y, else false.
lt $x lt $y value is true if $x is less than $y , else
false.
le $x le $y value is true if $x is less than or equal to $y,
else false.
cmp $x cmp $y value is -1 if $x is less than $y, 0 if the strings
are equal and 1 if $x is greater than $y.
CONTROL STRUCTURES:-
only simple programs are executed strictly in linear order. More complex
programs require that conditions be tested and acted upon appropriately some conditions will
require that a statement or block of statements be executed over and over again a specified
number of times, or until condition is met or satisfied.

The basic control structures in perl are:


1.if/else
2.nested if/else
3.unless
4.while
5.until
6.do......while
7.do......until
8.for
9.foreach
Besides these control structures perl also support switch control structure.

SUBROUTINE DATA TYPES:-


Subroutines are identified with an "&" symbol and subroutine name.
Ex:
$i=10;
$j=20;
$large=&max($i,$j);
print $large;
sub max
{
my $max=shift(@_)
foreach $arg(@_)
{
if ($max<$arg)
$max=$arg;
}
return $max;
}
SOME COMMANDS IN PERL:-

* Chop() - chop cutoff's or removes the last character in the scalar variable.
Ex:-#!g:\perl\bin\perl
$line="I LIKE YOU";
chop($line);
print"$line";
out put is I LIKE YO.
* Concatenation-The string concatenation operator is represented by a
period(".").
Ex:-#!g:\perl\bin\perl
$firstname="sanjay";
$lastname="kumar";
$fullname=$firstname . $lastname;
print "$fullname";
output is-sanjaykumar
* Chomp() - Removes the new line character if it presents in the string.
* <argv> - used to accept arguments through command line.
* shift() - Removes the first element from the array
Ex:-#!g:\perl\bin\perl
@cities=qw(H B C);
$delcity=shift(@cities);
print "@cities";
output is-("B","C")

* unshift() - Inserts the element at the first position of the array.


Ex:-#!g:\perl\bin\perl
@cities=qw(H B C)
unshift(@cities,"M","O");
print "@cities";
output is-("M","O","H","B","C")
* pop() - Removes the last element from the array.
#!g:\perl\bin\perl
@cities=qw(H B C);
$delcity=pop(@cities);
print "@cities";
output is-("H","B")
* Length()-It is used to find the length of the string.
Ex:-$name="I LIKE YOU";
$length=length($name);
* push() - Inserts the element at the end of the array.
Ex:-#!g:\perl\bin\perl
@cities=qw(H B C);
push(@names,"M","O");
print "@cities";
output is-("H","B","C","M","O")
* join() - We can join all the elements of the array.
join("#",@x) Now @x=(10# "svccs"# 4# "mca");

* split() - Based on yhe delimeter you can split the array.


split(/#/,@x) Now @x=(10, "svccs", 4, "mca");

* sort() - Based on the ASCII value the List will be sorted.


syntax:-sort(@cities);
* reverse()- List will be completely reversed.
syntax :-reverse(@cities);
* splice() : Simple and complex function which gives you the multiple functionality against
arrays.This function acts differently depending upon the no.of arguments passed.
By this function we can perform

* Delete * Insert *Replace operations.


If the number of arguments in splice function is 3 then it signifies the Delete operation.
If the number of arguments in splice function is 4 then it signifies the either Replace or Insert
operations.If the third parameter in the splice command is '0' then it signifies inserts operation
elseif the third parameter is other than '0' then it signifies Replace.

DELETE
splice(@x,0,1) ---- Removes the first value.
splice(@x,1,3) ---- Removes 3 elements starting from second position.
splice(@x,$#x/2,2) ---- Removes 2 elements from the middle position.

INSERT

$p="Hello World";
splice(@x,0,0,$p) Now @=(,"Hello World",10, "svccs", 4, "mca");
REPLACE

$val=100;
splice(@x,2,1,$val) Now @=(,"Hello World",100, "svccs", 4, "mca");

FILE HANDLERS:
In each and every language input and output both from standard devices and from
diskfiles is important.
Perl sends data to output devices and receives data from i/p devices via i/o channels. The
i/o channels are called filehandles. File input from the keyboard and output to the printer, perl
provides two filehandles they are STDIN,STDOUT respectively. There is also a prenamed
filehandle for I/O errors, STDERR.

The<STDIN > Filehandle:


When we want to get input from the user in perl programs we use the STDIN
filehandle. To get i/p from STDIN, you enclose the filehandle with perl's operator for reading
lines of text, the angle operator <>.
Syntax :-$var=<STDIN>; # it reads only one line
@vaa=<STDIN>; # it reads multiple lines
Ex :-#!g:\perl\bin\perl
while($line=<STDIN>)
{
print "$line";
last if($line eq "quit\n");
}

The < STDOUT >Filehandle:


For output to the standard output device the screen, perl uses the print
function. Print takes two arguments, the filehandle of the i/o channel being printed to, and a
string or list of comma-separated strings. Formated output can be obtained with printf finction.
Syntax :-print STDOUT "whatever you want to print";
* Syntax for opening a file: open(filehandler,name of file)
open(fh,"abc.dat") ------ opens file in read mode
open(fh,">abc.dat") ------ opens file in write mode
open(fh,">>abc.dat") ------ opens file in append mode

Ex: read.pl open(fh,"abc.dat");


$x=<fh>;
while($x)
{
print "$x","\n";
$x=<fh>;
}
Ex:write.pl
print "Enter your name:";
$name=<stdin>;
chop($name);
printf "Enter your age:";
$age=<stdin>;
chop($age);
$d="#",$n="\n";
$rec=$name.$d.$age.$n;
open(fh,">wrec.dat");
print fh $wrec;
# close(fh);

CONCLUSION
Perl basically evolved for extraction and report generation operations. Due to its
powerfulness it is widely used in string manipulations I/O and system tasks. Now perl is widely
used for writing C.G.I scripts.

BIBLIOGRAPHY

1.IVAN BAYROSS
2.perl from ground up--MICHAEL McMILLAN
3.URL:WWW.PERL.COM

Você também pode gostar