- Information
- AI Chat
Scripting Languages Manual - 08-07-2021
Scripting Languages
Recommended for you
Preview text
Department of Computer Science and Engineering
SCRIPTING LANGUAGES LAB MANUAL
III B Tech – II Semester
Branch: CSE
Mahatma Gandhi Institute of Technology
Chaitanya Bharathi Post, Gandipet, Hyderabad-500075(A. P.)
INDEX
Exp.
No
Name of the Experiment Page
No
1 Write a Ruby script to create a new string which is n copies of a given string where n is a non-negative integer
8
2 Write a Ruby script which accept the radius of a circle from the user and compute the parameter and area.
9
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.
10
4 Write a Ruby script to accept a filename from the user print the extension of that.
11
5 Write a Ruby script to find the greatest of three numbers 12 6 Write a Ruby script to print odd numbers from 10 to 1 13 7 Write a Ruby scirpt to check two integers and return true if one of them is 20 otherwise return their sum
14
8 Write a Ruby script to check two temperatures and return true if one is less than 0 and the other is greater than 100.
15
9 Write a Ruby script to print the elements of a given array 16 10 Write a Ruby program to retrieve the total marks where subject name and marks of a student stored in a hash
18
11 Write a TCL script to find the factorial of a number 19 12 Write a TCL script that multiplies the numbers from 1 to 10 20 13 Write a TCL script for Sorting a list using a comparison function 21 14 Write a TCL script to (i)create a list (ii )append elements to the list (iii)Traverse the list (iv)Concatenate the list
22
15 Write a TCL script to comparing the file modified times. 24 16 Write a TCL script to Copy a file and translate to native format. 25 17 a) Write a Perl script to find the largest number among three numbers. b) Write a Perl script to print the multiplication tables from 1-10 using subroutines.
26
18 Write a Perl script to print the multiplication tables from 1-10 using subroutines. a) Shift b) Unshift c) Push
28
19 a) Write a Perl script to substitute a word, with another word in a string. b) Write a Perl script to validate IP address and email address.
30
20 Write a Perl script to print the file in reverse order using command line arguments.
33
INTRODUCTION
About Ruby Programming Language
Ruby is a pure Object-Oriented language developed by Yukihiro Matsumoto (also known as Matz in the Ruby community) in the mid 1990’s in Japan. Everything in Ruby is an object except the blocks but there are replacements too for it i procs and lambda. The objective of Ruby’s development was to make it act as a sensible buffer between human programmers and the underlying computing machinery. Ruby has similar syntax to that of many programming languages like C and Java, so it is easy for Java and C programmers to learn. It supports mostly all the platforms like Windows, Mac, Linux.
Ruby is based on many other languages like Perl, Lisp, Smalltalk, Eiffel and Ada. It is an interpreted scripting language which means most of its implementations execute instructions directly and freely, without previously compiling a program into machine-language instructions. Ruby programmers also have access to the powerful RubyGems (RubyGems provides a standard format for Ruby programs and libraries). Beginning with Ruby programming:
- Finding a Compiler: Before starting programming in Ruby, a compiler is needed to compile and run our programs. There are many online compilers that can be used to start Ruby without installing a compiler: jdoodle/execute-ruby-online repl/ There are many compilers available freely for compilation of Ruby programs.
- Programming in Ruby: To program in Ruby is easy to learn because of its similar syntax to already widely used languages. Writing program in Ruby: Programs can be written in Ruby in any of the widely used text editors like Notepad++, gedit etc. After writing the programs save the file with the extension .rb
Advantages of Ruby:
The code written in Ruby is small, elegant and powerful as it has fewer number of lines of code. Ruby allows simple and fast creation of Web application which results in less hard work. As Ruby is free of charge that is Ruby is free to copy, use, modify, it allow programmers to make necessary changes as and when required. Ruby is a dynamic programming language due to which there is no tough rules on how to built in features and it is very close to spoken languages.
Disadvantages of Ruby: Ruby is fairly new and has its own unique coding language which makes it difficult for the programmers to code in it right away but after some practice its easy to use. Many programmers prefer to stick to what they already know and can develop. The code written in Ruby is harder to debug, since most of the time it generates at runtime, so it becomes difficult to read while debugging. Ruby does not have a plenty of informational resources as compared to other programming languages. Ruby is an interpreted scripting language, the scripting languages are usually slower than compiled languages therefore, Ruby is slower than many other languages.
Applications: Ruby is used to create web applications of different sorts. It is one of the hot technology at present to create web applications. Ruby offers a great feature called Ruby on Rails (RoR). It is a web framework that is used by programmers to speed up the development process and save time.
About Tool Command Language
Tcl is shortened form of Tool Command Language. John Ousterhout of the University of California, Berkeley, designed it. It is a combination of a scripting language and its own interpreter that gets embedded to the application, we develop with it. Tcl was developed initially for Unix. It was then ported to Windows, DOS, OS/2, and Mac OSX. Tcl is much similar to other unix shell languages like Bourne Shell (Sh), the C Shell (csh), the Korn Shell (sh), and Perl. It aims at providing ability for programs to interact with other programs and also for acting as an embeddable interpreter. Even though, the original aim was to enable programs to interact, you can find full-fledged applications written in Tcl/Tk.
Features of Tcl
The features of Tcl are as follows − Reduced development time. Powerful and simple user interface kit with integration of TK. Write once, run anywhere. It runs on Windows, Mac OS X, and almost on every Unix platform. Quite easy to get started for experienced programmers; since, the language is so simple that they can learn Tcl in a few hours or days. You can easily extend existing applications with Tcl. Also, it is possible to include Tcl in C, C++, or Java to Tcl or vice versa. Have a powerful set of networking functions. Finally, it's an open source, free, and can be used for commercial applications without any limit.
Applications
Tcl is a general-purpose language and you can find Tcl everywhere. It includes, Scalable websites that are often backed by databases. High performance web servers build with TclHttpd. Tcl with CGI based websites. Desktop GUI applications. Embedded applications.
1 a Ruby script to create a new string which is n copies of a given string where n is a non-negative integer.
Algorithm 1. Read one string 2. Using sort function we can sort the array element in descending order Code: puts "enter string" s1=gets puts "enter any no" no=gets.chomp_i if no > 0 puts s1 * no else puts "enter +ve no " end Output:
3 a Ruby script which accept the user's first and last name and print them in reverse order with a space between them. Code: puts "first name" fname=gets puts "enter last name" lname=gets rfn=fname rln=lname puts "#{fname} #{rln}" Output:
- Write a Ruby script to accept a filename from the user print the extension of that. Code: puts "enter filename" file = gets
fbname = File (file) # file name puts "File name: "+fbname
ffextn = File (file) # file extention puts "Extention: "+ffextn
path_name= File (file) # path name puts "Path name: "+path_name Output:
6 a Ruby script to print odd numbers from 10 to 1 Code: x= puts "odd nos between 10 to 1" while x > 0 if x % 2 != 0 puts "#{x}" end x= x- end Output:
- Write a Ruby scirpt to check two integers and return true if one of them is 20 otherwise return their sum Code: def check(a,b) if(a==20 || b==20) return true else return a+b end end puts "enter no 1" x=gets.chomp_i puts "enter no2" y=gets.chomp_i res=check(x,y) puts res Output:
9 a Ruby script to print the elements of a given array Code: arr1=[1,2,3,4,5,6,7,800,900] puts arr #arr1(999) adding elements at end fo the array #puts arr #puts arr1[4] display certian element #puts arr1[-1] display the elements in reverse dirction #puts arr1[3,5] diplay the elements form certian position and no of elements #puts arr1(5) know the element at the given pos #puts arr1(3) display first three elements #puts arr1(5) display last five elements #puts arr1 sort the array #puts arr1.sort stort the array in reverse order #x=[1,2,3] #y=[4,5,6] #z=x+y adding two arrays #puts z #puts arr1(3) delete the specified elemet #puts arr #arr1 delete the last element #puts arr #puts arr1 know the size of arry #puts arr1 know the size of arry #arr1 << 10 adding the elements at the end #puts arr #arr1(33) adding the elements at the end #puts arr #arr1(2,44)adding the eelenmntes at certian pos #puts arr
puts arr1 #delete the elements first elemet from array
Output:
- Write a TCL script to find the factorial of a number. Code: set i 1; set product 1; puts "enter no"; gets stdin x;# if i given x=
#set x 5; while {$i <= $x} { set product [expr $product * $i]; incr i; } puts "factorial of $x=$product"; Output:
- Write a TCL script that multiplies the numbers from 1 to 10 Code: proc times_table { x } { puts "Multiplication table for $x." for {set i 1 } { $i <= 10} {incr i } { set answer [expr $x * $i] puts "$x times $i = $answer" } }
proc run_table { } { puts -nonewline "Enter a number: " flush stdout gets stdin x times_table $x } run_table #end of program Output:
Scripting Languages Manual - 08-07-2021
Course: Scripting Languages
- Discover more from: