0
Perl - Practical Extraction and Report Language

Perl is an interpreted scripting language.

Perl is optimised for scanning arbitrary text files and system administration. 

It has built-in extended regular expression matching and replacement, a data-flow mechanism to improve security with setuid scripts and is extensible via modules that can interface to C libraries.


Installation :

sudo apt-get install perl

Compiling method :

perl filename.pl

e.g perl hello.pl 


Perl with MySQL Database Connectivity
 

use DBI;
use feature qw(switch);
my $dbh = DBI-> connect ("dbi:mysql:dbname","root","password");
print "\n 1.Insert  2.Update 3.Delete 4.Show\n Enter the option: ";
$n = <STDIN>;
given($n){
when(1) {&insert;}
when(2) {&update;}
when(3) {&deletes;}
when(4) {&selects;}
}
sub insert{
$sth= $dbh->prepare("insert into studtbl values(22,'gopi','IV','male')");
$sth-> execute();
}
sub update{
$sth2= $dbh->prepare("update studtbl set rno=561 where nme='faith' ");
$sth2-> execute();
}
sub deletes {
$sth3= $dbh->prepare("delete from studtbl where rno='222' ");
$sth3-> execute();}

sub selects{
$sth4=$dbh->prepare("select * from studtbl");
$sth4-> execute();
while (@results = $sth4->fetchrow()) {
    print $results[0].",".$results[1].",".$results[2].",".$results[3]." \n";
}
}

$dbh-> disconnect();

 

Note :  Look this 3rd line in the above program.

my $dbh = DBI-> connect ("dbi:mysql:dbname","root","password");

In this line change dbname as your database name and change password as your MySQL database password.


Table Creation in Mysql

mysql -u root -p 

Check the screenshot to create table





Before Insertion


After Insertion



After Updating 


After Deleting


Display all details in table


Post a Comment

 
Top