Ex no 4a:Concatenation of stringsusing PERL

Date:

Ex No 4b:Displaying odd or even number using PERL

Ex no 4c:ELECTRICITY BILL PREPARATION USING PERL

Date:

Aim:

To write a program for the preparing Electricity Bill using Perl (Open Source) and thus storing the data using the MySQL Database.

Algorithm:

Step1: Create the perl program in text editor.

Step2: Create the Database and the required table in Mysql.

Step3:Write the connectivity program for Mysql using Php and thus insert the records into the tables

Step5:Execute the programs and display the results.

Coding:

Electricitybill.perl

#Student Information System using PERL

use DBI;

use strict;

my $driver = "mysql";

my$database = "perl_electricity";

my $dsn = "DBI:$driver:database=$database";

my $userid = "root";

my $password = "root";

my $dbh = DBI->connect($dsn, $userid, $password,{AutoCommit => 1}) or die $DBI::errstr;

print "Enter the Consumer Service Number ";

my $cid = >;

print "Enter the Consumer Name ";

my $cname = >;

print "Enter the Consumer Address";

my $caddress = >;

print "Enter the Previous Reading ";

my $preading = >;

print "Enter the Current Reading ";

my $creading = >;

my $balancereading = $creading - $preading;

my $consumedprice = "";

if($balancereading> 0 & $balancereading<= 200)

{

$consumedprice = $balancereading * 0.50;

}

elsif($balancereading>= 201 & $balancereading<= 400)

{

$consumedprice = 100.00 + ($balancereading * 0.65);

}

elsif($balancereading>= 401 & $balancereading<= 600)

{

$consumedprice = 200.00 + ($balancereading * 0.80);

}

elsif($balancereading>= 601)

{

$consumedprice = 300.00 + ($balancereading * 1.00);

}

my $sth = $dbh->prepare("insert into electricity(consumerserviceno,consumername,consumeraddress,previousreading,currentreading,balancereading,totalamount)values($cid,'$cname','$caddress',$preading,$creading,$balancereading,$consumedprice)");

$sth->execute() or die $DBI::errstr;

my $sth = $dbh->prepare("select * from electricity");

$sth-execute() or die $DBI::errstr;

print "Number of rows found :" + $sth->rows + "\n";

while(my @row = $sth->fetchrow_array())

{

my ($cid,$cname,$caddress,$preading,$creading,$balancereading,$consumedprice) = @row;

print "Consumer ID: ",$cid,"\n";

print "Consumer Name: ",$cname,"\n";

print "Consumer Address: ",$caddress,"\n";

print "Previous Reading: ",$preading,"\n";

print "Current Reading: ",$creading,"\n";

print "Balance Reading: ",$balancereading,"\n";

print "Consumed Price: ",$consumedprice,"\n";

print "------\n";

}

$sth->finish();

Steps for MySQL:

1.To enter into mysql :

mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 63
Server version: 5.5.38-0ubuntu0.12.04.1 (Ubuntu)
Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.
Type 'help;' or '\h' for help.Type '\c' to clear the current input statement.
2.To display the available databases:

mysql> show databases;
+------+
| Database |
+------+
| information schema |
| mysql |
| performance schema |
| test |
+------+
4 rows in set (0.00 sec)
3.To create the new Database :

mysql> create database OSS_Lab;
Query OK, 1 row affected (0.01 sec)
mysql> show databases;
+------+
| Database |
+------+
| information_schema |
| OSS_Lab |
| mysql |
| performance_schema |
| test |
+------+
5 rows in set (0.00 sec)
4.To use the OSS_Lab Database:

mysql> use OSS_Lab;
Database changed

5.To create table details in theOSS_Lab Database:

mysql> create table bank(custidint not null primary key,custnamevarchar(20) not null,custaddressvarchar(20) not null,custdepositamountint not null,interestrate float not null,totalamount float not null);
Query OK, 0 rows affected (0.16 sec)
mysqldesc bank;
+------+------+------+-----+------+------+
| Field | Type | Null | Key | Default | Extra |
+------+------+------+-----+------+------+
| custid | int(11) | NO | PRI | NULL | |
| custname | varchar(20) | NO | | NULL | |
| custaddress | varchar(20) | NO | | NULL | |
| custdepositamount | int(11) | NO | | NULL | |
| interestrate | float | NO | | NULL | |
| totalamount | float | NO | | NULL | |
+------+------+------+-----+------+------+
6 rows in set (0.00 sec)

mysql> show tables;
+------+
| Tables_in_OSS_Lab |
+------+
| bank |
+------+
5 rows in set (0.00 sec)

mysql> select * from electricity;

+------+------+------+------+------+
| consumerserviceno| consumername | consumeraddress | previousreading | currentreading|

+------+------+
|balancereading |totalamount |

+------+------+------+------+------+
| 1001 | Ravi |3,car street,chennai | 112 | 150 |
| 38 | 19 |
+------+------+------+-----+------+------+
1 rows in set (0.00 sec)

mysqlexit

Result:

Thus the above program for the Electricity Bill Preparation using the open source(perl) is successfully executed and thus the output is verified.

Ex no 4dLIBRARY MANAGEMENT SYSTEM USING PERL

Date:

use DBI;

use strict;

my $driver = "mysql";

my $database = "perl_library";

my $dsn = "DBI:$driver:database=$database";

my $userid = "root";

my $password = "root";

my $dbh = DBI->connect($dsn, $userid, $password,{AutoCommit => 1}) or die $DBI::errstr;

print "Enter the Book ID ";

my $bid = >;

print "Enter the Book Name ";

my $bname = >;

print "Enter the Book Author ";

my $bauthor = >;

print "Enter the Book Publication ";

my $bpublication = >;

print "Enter the Book Price ";

my $bprice = >;

my $sth = $dbh->prepare("insert into lib(bookid,bookname,bookauthor,bookpublication,bookprice)values($bid,'$bname','$bauthor','$bpublication',$bprice)");

$sth-execute() or die $DBI::errstr;

my $sth = $dbh->prepare("select * from lib");

$sth-execute() or die $DBI::errstr;

print "Number of rows found :" + $sth->rows + "\n";

while(my @row = $sth->fetchrow_array())

{

my ($bid,$bname,$bauthor,$bpublication,$bprice) = @row;

print "Book ID:",$bid,"\n";

print "Book Name:",$bname,"\n";

print "Book Author:",$bauthor,"\n";

print "Book Publication:",$bpublication,"\n";

print "Book Price:",$bprice,"\n";

print "------\n";

}

$sth->finish();

Steps for MySQL:

1.To enter into mysql :

mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 63
Server version: 5.5.38-0ubuntu0.12.04.1 (Ubuntu)
Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.
Type 'help;' or '\h' for help.Type '\c' to clear the current input statement.
2.To display the available databases:

mysql> show databases;
+------+
| Database |
+------+
| information schema |
| mysql |
| performance schema |
| test |
+------+
4 rows in set (0.00 sec)
3.To create the new Database :

mysql> create database OSS_Lab;
Query OK, 1 row affected (0.01 sec)
mysql> show databases;
+------+
| Database |
+------+
| information_schema |
| OSS_Lab |
| mysql |
| performance_schema |
| test |
+------+
5 rows in set (0.00 sec)
4.To use the OSS_Lab Database:

mysql> use OSS_Lab;
Database changed

5.To create table details in theOSS_Lab Database:

mysql> create table lib(bookidint not null primary key,booknamevarchar(20) not null,bookauthorvarchar(20) not null,bookpublicationvarchar(20) not null,bookprice float not null);
Query OK, 0 rows affected (0.13 sec)

mysqldesc lib;

+------+------+------+-----+------+------+
| Field | Type | Null | Key | Default | Extra |
+------+------+------+-----+------+------+
| bookid | int(11) | NO | PRI | NULL | |
| bookname | varchar(20) | NO | | NULL | |
| bookauthor | varchar(20) | NO | | NULL | |
| bookpublication | varchar(20) | NO | | NULL | |
| bookprice | float | NO | | NULL | |
+------+------+------+-----+------+------+
5 rows in set (0.00 sec)

mysql> show tables;
+------+
| Tables_in_OSS_Lab |
+------+
| bank |
| coursereg |
| electricity |
| emp |
| library |
+------+
5 rows in set (0.00 sec)

mysqlselect * from lib;

+------+------+------+------+------+
| bookid | bookname | bookauthor | bookpublication | bookprice |
+------+------+------+------+------+
| 11055 | DSP | A.NagoorKani | TataMcGrawHill| 375 |
+------+------+------+------+------+
1 rows in set (0.00 sec)

mysqlexit