Web Technologies

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 12

1.

Perl –d

2) #! /usr/bin/perl

print "Hello world !\n"

3) $c= 10;

$f = 9/5*$c+32;

$cname = 'Introduction to Perl';

$fname = 'Introduction to webtech';

print "Course $cname: size $c\n";

print "Course $fname: size $f\n’;

4) #!/usr/bin/perl

use strict;

use warnings;

my $i=10;

my $j=10;
for(my $i=0; $i<=5; $i++)

print "*" x$i, "\n";

5) #!/usr/bin/perl

use strict;

use warnings;

my $i=10;

my $j=10;

for(my $i=0; $i<=10; $i++)

if($i%2==0)

print "" x$i;

else

print "*" x$i, "\n";

6) #!/usr/bin/perl
use strict;

use warnings;

my $i=10;

for(my $i=0; $i<=10; $i++)

for(my $k=$i; $k<10; $k++)

print "" x$k;

for(my $j=1; $j<=$i; $j++)

if($j%2==0)

print "" x$j;

else

print "*" x$j, "\n";

}
7) #!/usr/bin/perl

use strict;

use warnings;

my $i=10;

for(my $i=0; $i<=10; $i++)

if($j%2==0)

print "" x$j;

else

my $filename='C:\Users\Karan\Documents\triangles.dat';

open (my $fh, ">", $filename);

print $fh "*" x$j, "\n" ;

print "Written in the file Successfully";

OUTPUT:

8) #!/usr/bin/perl

use strict;
use warnings;

my $k;

my $l;

my $s;

my $u;

my $r;

print "Weight Format : Stones, Pounds, Ounces";

my $format =<STDIN>;

print "Enter Weight";

my $weight=<STDIN>;

if($format = "Stones")

my $k=$weight*6.35;

elsif($format ="Pounds")

my $l=$weight*0.45;

elsif($format ="Ounces")

my $u=$weight*0.028;

print "Height Format : meter, Inches";

my $hf=<STDIN>;

print"Enter Height";

my $height=<STDIN>;

if($hf="Meter")

my $s=$height;

elsif($hf="Inches")
{

my $r=$height*0.025;

print "The BMI is:\n";

if($hf='Meter' && $format='Stones')

my $bmi= $k/($s**2);

print "$bmi";

elsif($hf='Meter' && $format='Pounds')

my $bmi5= $l/($s**2);

print "$bmi5";

elsif($hf='Meter' && $format='Ounces')

my $bmi4= $u/($s**2);

print "$bmi4";

elsif($hf='Inches' && $format='Stones')

my $bmi3= $k/($r**2);

print "$bmi3";

elsif($hf='Inches' && $format='Pounds')

my $bmi2= $l/($r**2);

print "$bmi2";

elsif($hf='Inches' && $format='Ounces')

{
my $bmi1= $u/($r**2);

print "$bmi1";

OUTPUT:

9) my $filename='C:\Users\Karan\Documents\3.pl';

open(FILE, "< $filename") or die "can't open $file: $!";

$count++ while <FILE>;

print "No of line :$count";

OUTPUT:

10) #!/usr/bin/perl

use warnings;

my $filename='C:\Users\Karan\Documents\3.pl';

open(FILE,"<$filename") or die "Can't open 3.pl";

my $string = "apple";

while (<FILE>) {

if (/$string/)

print "found string $string\n"; }

else

{ print "did not find the string\n"; }


}

OUTPUT:

It searches line by line.

11. #!/usr/bin/perl

use warnings;

print "Celsius to Farenheit ";

print "Enter the value to convert :";

chomp(my $cel=<STDIN>);

while($cel==0){

print "The Converted Value is 0";

$f=(9*$cel/5+32);

print "The Converted value is: $f";

OUTPUT:

12)

my $name=<STDIN>;

chomp($name);

@arr=split(//,$name);
$count=@arr;

$num=0;

#print $count;

for ($i=0;$i<$count;$i++){

if ($arr[$i] eq $arr[$count-1]){

#print "$arr[$i] ===== $arr[$count]\n";

$count--;

}else{

$num++;

last;

if ($num == 0){

print "Word is palindrome!!!";

}else{

print "Word is not a Palindrome!!!";

OUTPUT:

18)

#!/usr/bin/perl

use strict;

use warnings;

print "Please Enter the File Name : ";

my $file_name = <STDIN>;

print "Enter student marks: ";


my $mark=<STDIN>;

chomp($mark);

chomp($file_name);

open (my $fh, '<', $file_name) or die "Can't Open $file_name $!\n";

while (my $line = <$fh>) {

if(<CODE> $line == $mark)

print"$line";

else

print"<CODE> $line";

OUTPUT:

19) #!/usr/bin/perl

use strict;

use warnings;

print "Please Enter the File Name : ";

my $file_name = <STDIN>;

print"Median = $median \n";

chomp($file_name);

chomp($median);

open (my $fh, '<', $file_name) or die "Can't Open $file_name $!\n";

while (my $line = <$fh>) {

my $median = <CODE> $line ">" ($marks > {count = 1 && 2))/2;


print "$median";

20.

#!/usr/bin/perl

use strict;

use warnings;

print "Please Enter the File Name : ";

my $file_name = <STDIN>;

chomp($file_name);

open (my $fh, '<', $file_name) or die "Can't Open $file_name $!\n";

while (my $line = <$fh>) {

my $DESIRED_LINE_NUMBER1 = 1;

my $DESIRED_LINE_NUMBER2 = 2;

my $LINE = $line[$DESIRED_LINE_NUMBER1];

my $LINE2 = $line[$DESIRED_LINE_NUMBER2];

my $product = $LINE * $LINE2;

chomp($product);

print "Product = $product";

print"$line";

OUTPUT:

24)
1) /Fred/

2) /[Fred Bloggs]/

3) preg_match( '/^[A-Z0-9]{10}$/')

4) preg_match( '/^[A]{10}$/')

5) /^[ATAT]{7}/ and /^[ATAT]{12}/

6) /[CGCG][^A]^[A-Z 0-9]={3}[ACTT ACGT]/

7) /[ACG]^[A-Z 0-9]={3}^[s]={10}^[a]^[A-Z 0-9]/

You might also like