Professional Documents
Culture Documents
SCRIPTING LANGUAGES
LABORATORY MANUAL
ROLL NO :………………………………………………………………
BRANCH:……………………………..SECTION:……………………
YEAR: …………………………SEMESTER:………………………..
0 0 2 1
Course Objectives:
To Understand the concepts of scripting languages for developing web basedprojects
To understand the applications of the Ruby, TCL, Perl scriptinglanguages
Course Outcomes:
AbilitytounderstandthedifferencesbetweenScriptinglanguagesandprogramminglangua
ges
Able to gain some fluency programming in Ruby, Perl,TCL
List of Experiments
1. Write a Ruby script to create a new string which is n copies of a given string
7. Write a Ruby scirpt to check two integers and return true if one of them is 20
10. Write a Ruby program to retrieve the total marks where subject name and marks
12. Write a TCL script that multiplies the numbers from 1 to10
13. Write a TCL script for Sorting a list using a comparison function
14. Write a TCL script to (i)create a list (ii )append elements to the list (iii)Traverse
17. a) Write a Perl script to find the largest number among threenumbers.
b) Write a Perl script to print the multiplication tables from 1-10 using subroutines.
18. Write a Perl program to implement the following list of manipulatingfunctions
a)Shift
b)Unshift
c)Push
19. a) Write a Perl script to substitute a word, with another word in astring.
2 WriteaRubyscriptwhichaccepttheradiusofacirclefromtheusera
ndcomputetheparameter and area.
3 Write a Ruby script which accept the user's first and last
name and print them in reverse order with a space between
them
4 Write a Ruby script to accept a filename from the user print the
extension of that
8 WriteaRubyscripttochecktwotemperaturesandreturntrueifonei
slessthan0andtheother is greater than100
a)Shift
b)Unshift
c)Push
Experiments-1 Write a Ruby script to create a new string which is n copies of a given
Date: string where n is a non-negative integer.
Source Code
#!/usr/bin/ruby
def multiple_string(str, n)
return str*n
end
OUTPUT
ruby
rubyruby
rubyrubyruby
rubyrubyrubyruby
rubyrubyrubyrubyruby
Experiments-2 Write a Ruby script which accept the radius of a circle from the user and
Date: compute the parameter and area.
Source Code:
#!/usr/bin/ruby
circleRadius = gets.to_f
radius = gets.to_f
OUTPUT
Experiments-3 Write a Ruby script which accept the user's first and last name and print
Date: them in reverse order with a space betweenthem
Source Code
#!/usr/bin/ruby
fname=gets.chomp
lname=gets.chomp
puts "#{lname}#{fname}"
OUTPUT
nikitha
reddyvishnu
reddyvishnunikitha
Experiments-4 Write a Ruby script to accept a filename from the user print the
Date: extension of that.
Source Code
#!/usr/bin/ruby
file ="/user/system/test.rb"
# file name
fbname=File.basename file
# basename
bname=File.basename file,".rb"
# fileextention
ffextn=File.extname file
# path name
path_name=File.dirname file
OUTPUT
Source Code
#!/usr/bin/ruby
x,y,z=10,9,25
else
end
(or)
x = Integer(gets.chomp)
y = Integer(gets.chomp)
z = Integer(gets.chomp)
if (x == y) && (x == z)
end
OUTPUT
y = 5 is greatest.
Source Code
#!/usr/bin/ruby
9.step 1,-2do|x|
puts "#{x}"
end
OUTPUT
Experiments-7 Write a Ruby script to check two integers and return true if one of them is
Date: 20 otherwise return their false statement.
Source Code
#!/usr/bin/ruby
defmakes20(x,y)
end
print makes20(10,10),"\n"
print makes20(40,10),"\n"
print makes20(15,20)
OUTPUT
true
false
true
Experiments-8 Write a Ruby script to check two temperatures and return true if one is
Date: less than 0 and the other is greater than 100.
Source Code
#!/usr/bin/ruby
return ( temp1 < 0 && temp2 > 100 ) || ( temp1 > 100 && temp2 < 0 );
end
OUTPUT
true
true
false
Source Code
#!/usr/bin/ruby
puts array_element
end
OUTPUT
Ruby
2.3
2020-03-16 17:16:14 +0000
Experiments-10 Write a Ruby script to retrieve the total marks where subject name and
Date: marks of a student stored in a hash.
Source Code
#!/usr/bin/ruby
student_marks = Hash.new 0
student_marks['Literature'] = 74
student_marks['Science'] = 89
student_marks['Math'] = 91
total_marks = 0
student_marks.each {|key,value|
total_marks +=value
OUTPUT
Source Code:
set fact 1
for {set i 0} {$i<= 6} {incri} {
puts "$i! = $fact"
set fact [expr {$fact * ($i + 1)}]
}
OUTPUT:
$tclshmain.tcl
0! = 1
1! = 1
2! = 2
3! = 6
4! = 24
5! = 120
6! = 720
Experiments-12 Write a TCL script that multiplies the numbers from 1 to10
Date:
Source code:
set i 1
while {$i <= 10} {
puts $i
incr i
}
output:
1*1=1
1*2=2
2*3=6……….
Experiments-13
Date: Write a TCL script for Sorting a list using a comparison function
Source Code
#!/usr/bin/tclsh
set nums{ 1 5 4 3 6 7 9 2 11 0 8 2 3 }
puts $concatsort
OUTPUT
Experiments-14 Write a TCL script to (i)create a list (ii )append elements to the list
Date: (iii)Traverse the list (iv)Concatenate thelist
TCL script to
(i)create a list
Source Code
#!/usr/bin/tclsh
set colorList1 {red green blue}
set colorList2 [list red green blue]
set colorList3 [split "red_green_blue" _]
puts $colorList1
puts $colorList2
puts $colorList3
OUTPUT
Source Code
#!/usr/bin/tclsh
puts $var
OUTPUT
Source code
#!/usr/bin/tclsh
set i 0
incr i
OUTPUT
Traverse of the list
Monday
Tuesday
Wednesday
Thursday
Friday
Saturday
Sunday
(iv)Concatenate thelist
Source Code
#!/usr/bin/tclsh
set animals1 { lion eagle elephant dog cat }
set animals2 { giraffe tiger horse dolphin }
set animals [concat $animals1 $animals2]
puts $animals
OUTPUT
Source Code
return 1
} else {
OUTPUT
Time files
Experiments-16 Write a TCL script to Copy a file and translate to native format.
Date:
Source code:
output:
Experiments-17 a) Write a Perl script to find the largest number among threenumbers.
Date:
Source Code
#!/usr/bin/perl
print "enter a value";
$x=<stdin>;
print "enter b value";
$y=<stdin>;
print "enter c value";
$z=<stdin>;
if($a > $b) //if compares string use gt ,lt,le,ge
{
if($a> $c)
{
print " $a is largest number\n";
}
else
{
print " $c is largest number\n";
}
}
elsif($b >$c)
{
print " $b is largest number";
}
else
{
print " $c is largest nnumber";
}
OUTPUT
Enter a value 4
Enter b value 6
Enter c value 5
6 is largest number
Experiments-17
b) Write a Perl script to print the multiplication tables from 1-10 usings
Date:
Source Code
for($i=1;$i<=10;$i++)
{
$a[$i]=$i;
for($i=1;$i<=10;$i++)
{
for($j=1;$j<=10;$j++)
{
print(($a[$j]*$a[$i])," ");
}
print "\n\n";
}
Output:
1 2 3 4 5 6 7 8 9 10
2 4 6 8 10 12 14 16 18 20
3 6 9 12 15 18 21 24 27 30
4 8 12 16 20 24 28 32 36 40
5 10 15 20 25 30 35 40 45 50
6 12 18 24 30 36 42 48 54 60
7 14 21 28 35 42 49 56 63 70
8 16 24 32 40 48 56 64 72 80
9 18 27 36 45 54 63 72 81 90
10 20 30 40 50 60 70 80 90 100
Experiments-18
Write a Perl program to implement the following list of manipulating
Date:
function a) shift b)Unshift c)Push
a)Shift
Source Code
#!/usr/bin/perl
OUTPUT
b)Unshift
Source Code
#!/usr/bin/perl
OUTPUT
c) Push
Source Code
#!/usr/bin/perl
OUTPUT
Experiments-19 a) Write a Perl script to substitute a word, with another word in astring.
Date:
Source Code
my $string = q|
completely different.
|;
$string =~ s/\bc\w*\b/badger/ig;
print $string;
print $string;
OUTPUT
Experiments-19 (b) Write a Perl script to validate IP address and email address.
Date:
Source Code
my @ip = ("0123.456.789.654",
"a123.456.789.654",
"123.456.789.6543",
"111.222.333.444")
if ( $ip =~ /(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/)
else
for $ip(@ip) {
if ( $ip =~ /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/) {
else
OUTPUT
Experiments-20 Write a Perl script to print the file in reverse order using command line
Date: arguments
Source Code
OUTPUT