0% found this document useful (0 votes)
72 views37 pages

TCL Scripting Language

Tcl is a dynamic scripting language designed for controlling and extending applications, with its toolkit Tk enabling GUI development. It offers rapid development, ease of use, and supports Unicode, making it suitable for various applications. The document also includes several sample Tcl scripts for tasks like calculating factorials, generating multiplication tables, sorting lists, and file manipulation.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
72 views37 pages

TCL Scripting Language

Tcl is a dynamic scripting language designed for controlling and extending applications, with its toolkit Tk enabling GUI development. It offers rapid development, ease of use, and supports Unicode, making it suitable for various applications. The document also includes several sample Tcl scripts for tasks like calculating factorials, generating multiplication tables, sorting lists, and file manipulation.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 37

TCL SCRIPTING LANGUAGE

Introduction:
Tcl is a dynamic language (also known as a scripting language) for
controlling and extending applications; its name stands for ―tool
command language.‖ Tcl provides general programming facilities sufficient
for most applications. Furthermore, Tcl is both embeddable and extensible.
Its interpreter is a library of C functions that can easily be incorporated into
applications, and each application can extend the core Tcl features with
additional commands either unique to the application or provided by add-on
libraries (referred to as extensions in the Tcl community).
The official pronunciation for Tcl is ―tickle,‖ although ―tee-see-ell‖ is
also used frequently. Tk is pronounced ―tee-kay.‖
One of the most useful extensions to Tcl is Tk, which is a toolkit for
developing graphical user interface (GUI) applications. Tk extends the core
Tcl facilities with commands for building user interfaces, so that you can
construct GUIs by writing Tcl scripts instead of C code. Like Tcl, Tk is
implemented as a library of C functions so it can be used in many different
applications.
Benefits:
Together, Tcl and Tk provide several benefits to application
developers and users. The first benefit is rapid development. Many
interesting applications higher level than you would in C/C++ or Java, and
Tk hides many of the details that C or Java programmers must address.
Compared to low-level toolkits, there is much less to learn in order to use Tcl
and Tk, and much less code to write. New Tcl/Tk users often can create
interesting user interfaces after just a few hours of learning, and many people
have reported tenfold reductions in code size and development time when
they switched from other toolkits to Tcl and Tk.
Another reason for rapid development with Tcl and Tk is that Tcl is
an interpreted language. When you use a Tcl application, you can generate
and execute new scripts on the fly without recompiling or restarting the
application. This allows you to test out new ideas and fix bugs rapidly. Since
Tcl is interpreted, it executes more slowly than compiled C code; but internal
optimizations, such as bytecode compilation coupled with ever increasing
processor power, have erased most of the perceived performance advantages
of compiled languages.
Tcl was also the first dynamic language to have native Unicode
support. As a result, Tcl applications can handle text in virtually any of the
world’s written languages. Tcl requires no extensions to process text in any
of the Unicode-supported scripts, and standard extensions such as msgcat
provide simple localization support.
Another significant benefit is that Tcl and most of its extensions are
freely available as open source. Tcl and Tk follow the so-called BSD license,
which allows anyone to download, inspect, modify, and redistribute Tcl/Tk
without charge.
Tcl is an excellent ―glue language.‖ A Tcl application can
include many different extensions, each of which provides an interesting set
of Tcl commands. Tk is one example of a library package; many other
packages have been developed by the Tcl/Tk community, and you can also
write your own packages. Tcl scripts for such applications can include
commands from any of the packages.
Additionally, Tcl makes it easy for applications to have powerful
scripting languages. For example, to add scripting capability to an existing
application, all you need do is implement a few new Tcl commands that
provide the basic features of the application. Then you can link your new
commands with the Tcl library to produce a full-function scripting language
that includes both the commands provided by Tcl (called the Tcl core) and
those that you wrote.
Tcl also provides user convenience. Once you learn Tcl and Tk, you
will be able to write scripts for any Tcl and Tk application merely by
learning the few application-specific commands for the new application. This
should make it possible for more users to personalize and enhance their
applications.
Additional Features of Tcl and Tk:
some of the most useful features
Arrays, dictionaries, and lists — Tcl provides associative arrays and
dictionaries for storing key-value pairs efficiently and lists for managing
aggregates of data.
More control structures — Tcl provides several additional commands for
controlling the flow of execution, such as eval, for, foreach, and switch.
String manipulation — Tcl contains a number of commands for
manipulating strings, such as measuring their length, regular expression
pattern matching and substitution, and format conversion.
File access — You can read and write files from Tcl scripts and retrieve
directory information and file attributes such as size and creation time.
More widgets — Tk contains many widget classes besides those shown
here, such as menus, scrollbars, a drawing widget called a canvas, and a text
widget that makes it easy to achieve hypertext effects.
Access to other windowing features — Tk provides commands for for
communicating with the window manager (to set the window’s title, for
Scripting Language Lab Work Book

example), a command for retrieving the selection, and a command to manage


the input focus.
Interapplication communication — Tcl includes the ability to
communicate between applications through interprocess pipes and TCP/IP
sockets.
C interfaces—Tcl provides C library procedures that you can use to define
new Tcl commands in C.
Scripts, Commands, and Words:
A Tcl script consists of one or more commands. Commands are
separated by newlines or semicolons. For example,
set a 24
set b 15
is a script with two commands separated by a newline character. The same
script could be written on a single line using a semicolon separator:
set a 24; set b 15
Each command consists of one or more words, where the first word is
the name of a command and additional words are arguments to that
command.
Words are separated by spaces or tabs, which are generally referred
to as either whitespace characters or just whitespace. Each of the commands
in the preceding examples has three words. There may be any number of
words in a command, and each word may have an arbitrary string value. The
whitespace that separates words is not part of the words, nor are the newlines
and semicolons that terminate commands.
Scripting Language Lab Work Book

PROGRAM-11
Factorial of a given Number
Objective: To Write a TCL script to find the factorial of a number.

Tools Required:
1. PC
2. OS- Linux
3. Atom Text Editor
4. TCL version above 8.

Program:
proc fact {num} {
if {$num} {
return [expr {$num * [fact [incr num -1]]}]
} else {
return 1
}
}

proc fact_run {} {
puts -nonewline "Compute the factorial of: "
flush stdout
set num [gets stdin]
if { [expr {int(abs($num))}] != $num } {
puts "Sorry: only non-negative integers allowed"
} else {
puts [fact $num]
}
}

fact_run
Scripting Language Lab Work Book

Outputs:

Procedure:
1. Switch on the Computer and select the operating system Linux or
windows.
2. Open terminal or cmd and type tclsh–v and press enter then give
command info patchlevel it gives current version of tcl.Then type exit.
3. Open the text editor or notepad and write the program and save as it
with extension ―.tcl‖
4. Open the terminal or command prompt enter following commands:
i) cd\
ii) cd<space><path of the folder where the program file is saved>
5. Now run the program in terminal or command prompt using the
command: tclsh<space><filename.tcl>
6. Note down the outputs and make a screenshot of them.

Result: Hence TCL script is written to find the factorial of a given number.

Signature of the Faculty


Scripting Language Lab Work Book

PROGRAM-12
Display Multiplication table of a given Number
Objective: To Write a TCL script that multiplies the numbers from 1 to 10.

Tools Required:
1. PC
2. OS- Linux
3. Atom Text Editor
4. TCL version above 8.

Program:
proc times_table { num } {
puts "Multiplication table for $num."
for {set i 1 } { $i <= 10} {incr i } {
set answer [expr $num * $i]
puts "$num X $i = $answer"
}
}
proc run_table { } {
puts -nonewline "Enter a number: "
flush stdout
set num [gets stdin]
times_table $num
}

run_table
Scripting Language Lab Work Book

Outputs:

Procedure:
1. Switch on the Computer and select the operating system Linux or
windows.
2. Open terminal or cmd and type tclsh–v and press enter then give
command info patchlevel it gives current version of tcl.Then type exit.
3. Open the text editor or notepad and write the program and save as it
with extension ―.tcl‖
4. Open the terminal or command prompt enter following commands:
i) cd\
ii) cd<space><path of the folder where the program file is saved>
5. Now run the program in terminal or command prompt using the
command: tclsh<space><filename.tcl>
6. Note down the outputs and make a screenshot of them.
Result: Hence TCL script is written that multiplies the numbers from 1 to 10

Signature of the Faculty


Scripting Language Lab Work Book

PROGRAM-13
Sorting a List
Objective: To Write a TCL script for sorting a list using a comparison
function.

Tools Required:
1. PC
2. OS- Linux
3. Atom Text Editor
4. TCL version above 8.

Program:
proc mycompare {arg1 arg2} {
if {[regexp {test(\d+)} $arg1 -> n1] && [regexp {test(\d+)} $arg2 -> n2]}
{
return [expr {$n1 - $n2}]
}
return [string compare $arg1 $arg2]
}

set list1 {Antennas DSP BST VLSIDESIGN ESD}


set list2 {1 10 20 25 6 4 2 15}
set list3{Antennas 20 10 25 DSP}
puts [lsort -command mycompare
$list1] puts [lsort -command mycompare
$list2] puts [lsort -command mycompare
$list3]
Scripting Language Lab Work Book

Outputs:

Procedure:
1. Switch on the Computer and select the operating system Linux or
windows.
2. Open terminal or cmd and type tclsh–v and press enter then give
command info patchlevel it gives current version of tcl.Then type exit.
3. Open the text editor or notepad and write the program and save as it
with extension ―.tcl‖
4. Open the terminal or command prompt enter following commands:
i) cd\
ii) cd<space><path of the folder where the program file is saved>
5. Now run the program in terminal or command prompt using the
command: tclsh<space><filename.tcl>
6. Note down the outputs and make a screenshot of them.
Result: Hence TCL script is written for sorting the given list.

Signature of the Faculty


Scripting Language Lab Work Book

PROGRAM-14
Manipulations on List
Objective: To Write a TCL script to (i) create a list (ii) append elements to
the list (iii) Traverse the list (iv) Concatenate the list
Tools Required:
1. PC
2. OS- Linux
3. Atom Text Editor
4. TCL version above 8.
Program:
#Creating list in three different ways
set subject1 {Antennas BST DSP ESD VLSI}
set subject2 [list Antennas BST DSP ESD
VLSI]
set subject3 [split "Antennas_BST_DSP_ESD_VLSI" _]
puts $subject1
puts $subject2
puts $subject3
#Appending new value
set var SLL
append var " " $subject1
puts $var
#Transerse the list
set rev [lreverse
$var] puts $rev
#Concatinating two strings
set conc [concat $subject1 $var]
11
Scripting Language Lab Work Book

puts $conc

12
Scripting Language Lab Work Book

Outputs:

Procedure:
1. Switch on the Computer and select the operating system
Linux/windows.
2. Open terminal or cmd and type tclsh–v and press enter then give
command info patchlevel it gives current version of tcl.Then type exit.
3. Open the text editor or notepad and write the program and save as it
with extension ―.tcl‖
4. Open the terminal or command prompt enter following commands:
i) cd\
ii) cd<space><path of the folder where the program file is saved>
5. Now run the program in terminal or command prompt using the
command: tclsh<space><filename.tcl>
6. Note down the outputs and make a screenshot of them.
Result: Hence TCL script is written for creating, appending, reverse and
concatenate of a list.

Signature of the Faculty

13
Scripting Language Lab Work Book

PROGRAM-15
Comparing File Modification time
Objective: To Write a TCL script to comparing the file modified times.
Tools Required:
1. PC
2. OS- Linux
3. Atom Text Editor
4. TCL version above 8.
Program:
proc newer { file1 file2 } {
if {![file exists $file2]} {
return 1
} else {
# Assume file1 exists
expr {[file mtime $file1] > [file mtime $file2]}
}
}
Outputs:

14
Scripting Language Lab Work Book

Procedure:
1. Switch on the Computer and select the operating system
Linux/windows.
2. Open terminal or cmd and type tclsh–v and press enter then give
command info patchlevel it gives current version of tcl.Then type exit.
3. Open the text editor or notepad and write the program and save as it
with extension ―.tcl‖
4. Open the terminal or command prompt enter following commands:
i) cd\
ii) cd<space><path of the folder where the program file is saved>
5. Now run the program in terminal or command prompt using the
command: tclsh<space><filename.tcl>
6. Note down the outputs and make a screenshot of them.
Result: Hence TCL script is written for comparing file modification time.

Signature of the Faculty

15
Scripting Language Lab Work Book

PROGRAM-16
Translation of a file
Objective: To Write a TCL script Copy a file and translate to native format.
Tools Required:
1. PC
2. OS- Linux
3. Atom Text Editor
4. TCL version above 8.
Program:
proc File_Copy {src dest} {
if {[file isdirectory $src]} {
file mkdir $dest
foreach f [glob -nocomplain [file join $src *]] {
File_Copy $f [file join $dest [file tail $f]]
}
return
}
if {[file isdirectory $dest]} {
set dest [file join $dest [file tail $src]]
}
set in [open $src]
set out [open $dest w]
puts -nonewline $out [read
$in] close $out ; close $in
}

16
Scripting Language Lab Work Book

Outputs:

Procedure:
1. Switch on the Computer and select the operating system
Linux/windows.
2. Open terminal or cmd and type tclsh–v and press enter then give
command info patchlevel it gives current version of tcl.Then type exit.
3. Open the text editor or notepad and write the program and save as it
with extension ―.tcl‖
4. Open the terminal or command prompt enter following commands:
i) cd\
ii) cd<space><path of the folder where the program file is saved>
5. Now run the program in terminal or command prompt using the
command: tclsh<space><filename.tcl>
6. Note down the outputs and make a screenshot of them.
Result: Hence TCL script is written for translating a file into native format.

Signature of the Faculty

17
Scripting Language Lab Work Book

PERL SCRIPTING LANGUAGE


Getting Started:
We think that Perl is an easy language to learn and use, and we hope
to convince you that we’re right. One thing that’s easy about Perl is that you
don’t have to say much before you say what you want to say. In many
programming languages, you have to declare the types, variables, and
subroutines you are going to use before you can write the first statement of
executable code. And for complex problems demanding complex data
structures, declarations are a good idea. But for many simple, everyday
problems, you’d like a programming language in which you can simply say:
print "Howdy, world!\n";
and expect the program to do just that.
Perl is such a language. In fact, this example is a complete program,1
and if you feed it to the Perl interpreter, it will print ―Howdy, world!‖
on your screen. (The \n in the example produces a newline at the end of the
output.)
And that’s that. You don’t have to say much after you say what you
want to say, either. Unlike many languages, Perl thinks that falling off the
end of your program is just a normal way to exit the program. You certainly
may call the exit function explicitly if you wish, just as you may declare
some of your variables, or even force yourself to declare all your variables.
But it’s your choice. With Perl you’re free to do The Right Thing, however
you care to define it.
There are many other reasons why Perl is easy to use, but it would be
pointless to list them all here, because that’s what the rest of the book is for.
The devil may be in the details, as they say, but Perl tries to help you out
down there in the hot place, too. At every level, Perl is about helping you get
18
Scripting Language Lab Work Book

from here to there with minimum fuss and maximum enjoyment. That’s why
so many Perl programmers go around with a silly grin on their face.
Natural and Artificial Languages:
Languages were first invented by humans, for the benefit of humans.
In the annals of computer science, this fact has occasionally been forgotten.
Since Perl was designed (loosely speaking) by an occasional linguist, it was
designed to work smoothly in the same ways that natural language works
smoothly. Naturally, there are many aspects to this, since natural language
works well at many levels simultaneously. We could enumerate many of
these linguistic principles here, but the most important principle of language
design is that easy things should be easy, and hard things should be possible.
(Actually, that’s two principles.) They may seem obvious to you, but many
computer languages fail at one or the other.
Natural languages are good at both because people are continually
trying to express both easy things and hard things, so the language evolves to
handle both. Perl was designed first of all to evolve, and indeed it has
evolved. Many people have contributed to the evolution of Perl over the
years. We often joke that a camel is a horse designed by a committee, but if
you think about it, the camel is pretty well adapted for life in the desert. The
camel has evolved to be relatively self-sufficient. (On the other hand, the
camel has not evolved to smell good. Neither has Perl.) This is one of the
many strange reasons we picked the camel to be Perl’s mascot, but it doesn’t
have much to do with linguistics.
Now when someone utters the word ―linguistics‖, many folks focus
in on one of two things. Either they think of words, or they think of
sentences. But words and sentences are just two handy ways to
―chunk‖
19
Scripting Language Lab Work Book

speech. Either may be broken down into smaller units of meaning or

20
Scripting Language Lab Work Book

combined into larger units of meaning. And the meaning of any unit depends
heavily on the syntactic, semantic, and pragmatic context in which the unit is
located. Natural language has words of various sorts: nouns and verbs and
such. If someone says ―dog‖ in isolation, you think of it as a noun, but you
can also use the word in other ways. That is, a noun can function as a verb,
an adjective, or an adverb when the context demands it. If you dog a dog
during the dog days of summer, you’ll be a dog tired dogcatcher. Perl also
evaluates words differently in various contexts. We will see how it does that
later. Just remember that Perl is trying to understand what you’re saying, like
any good listener does. Perl works pretty hard to try to keep up its
end of the bargain. Just say what you mean, and Perl will usually ―get
it‖. (Unless you’re talking nonsense, of course—the Perl parser understands
Perl a lot better than either English or Swahili.)
But back to nouns. A noun can name a particular object, or it can
name a class of objects generically without specifying which one is currently
being referred to. Most computer languages make this distinction, only we
call the particular one a value and the generic one a variable. A value just
exists somewhere, who knows where, but a variable gets associated with one
or more values over its lifetime. So whoever is interpreting the variable has
to keep track of that association. That interpreter may be in your brain or in
your computer.
Perl Features:
 Perl takes the best features from other languages, such as C, awk,
sed, sh, and BASIC, among others.
 Perls database integration interface DBI supports third-party
databases including Oracle, Sybase, Postgres, MySQL and others.
 Perl works with HTML, XML, and other mark-up languages.
21
Scripting Language Lab Work Book

 Perl supports Unicode.


 Perl is Y2K compliant.
 Perl supports both procedural and object-oriented programming.
 Perl interfaces with external C/C++ libraries through XS or SWIG.
 Perl is extensible. There are over 20,000 third party modules
available from the Comprehensive Perl Archive Network (CPAN).
 The Perl interpreter can be embedded into other systems.
Running Perl:
You can enter perl and start coding right away in the interactive interpreter
by starting it from the command line. You can do this from Unix, DOS, or
any other system, which provides you a command-line interpreter or shell
window.
$perl -e <perl code> #
Unix/Linux or
C:>perl -e <perl code> # Windows/DOS

22
Scripting Language Lab Work Book

PROGRAM-17
Finding Largest Number and Displaying Multiplication table
Objective: a) To Write a Perl script to find the largest number among three
numbers.
b) To Write a Perl script to print the multiplication tables from 1-10 using
subroutines.
Tools Required:
1. PC
2. OS- Linux
3. Atom Text Editor
4. PERL version above 5.
Program a:
print "Enter a number\n";
chomp($a=<stdin>);
print "Enter second number\n";
chomp($b=<stdin>);
print "Enter third number\n";
chomp($c=<stdin>);
$big=0;
$equal=0;
if($a eq $b)
{
$big = $a;
$equal = $a;
}
elsif($a > $b){
$big=$a;
23
Scripting Language Lab Work Book

24
Scripting Language Lab Work Book

else{
$big = $b;
}
if($equal eq $c){
print "All numbers are same";
}
elsif($big < $c){
$big = $c;
}
else{
print "The biggest number is $big \n";
}
Outputs:

25
Scripting Language Lab Work Book

Program b:
use strict;
use warnings;
use diagnostics;
use 5.01000;

&table( 3 );

sub table {

my $i = 1;
my $loop;

foreach $loop (@_) {


warn " loop $loop \n";
for ( $i ; $i <= 10 ; $i++ ) {
my $ans = $i * $loop;
print "$ans ";
}
print "\n";
}
}
Outputs:

26
Scripting Language Lab Work Book

Procedure:
1. Switch on the Computer and select the operating system
Linux/windows.
2. Open terminal or cmd and type perl –v and press enter then it gives
current version of perl.
3. Open the text editor or notepad and write the program and save as it
with extension ―.pl‖
4. Open the terminal or command prompt enter following commands:
i) cd\
ii) cd<space><path of the folder where the program file is saved>
5. Now run the program in terminal or command prompt using the
command: perl<space><filename.pl>
6. Note down the outputs and make a screenshot of them.
Result: Hence PERL script is written for finding greater number and for
displaying multiplication table.

Signature of the Faculty

27
Scripting Language Lab Work Book

PROGRAM-18
SHIFT, UNSHIFT and PUSH OPERATIONS
Objective: To write a Perl program to implement the following list of
manipulating functions
a) Shift b)Unshift c) Push

Tools Required:
1. PC
2. OS- Linux
3. Atom Text Editor
4. PERL version above 5.
Program:
#SHIFT
# Initalizing the array
@x = ('ECE', 'CSE', 'CIVIL', 'IT');

# Print the Inital array


print "Original array: @x \n";

# Prints the value returned


# by shift function
print "Value returned by shift: ",
shift(@x);

# Array after shift operation


print "\nUpdated array: @x";

28
Scripting Language Lab Work Book

#UNSHIFT
# Initalizing the array
@x = ('Java', 'C', 'C++');

# Print the Inital array


print "Original array: @x \n";

# Prints the number of elements


# returned by unshift
print "No of elements returned by unshift:
", unshift(@x, 'PHP', 'JSP');

# Array after unshift


operation print "\nUpdated
array: @x";

#PUSH
# Initalizing the array
@x = ('ECE', 'CSE', 'CIVIL', 'IT');

# Print the Inital array


print "Original array: @x \n";

# Pushing multiple values in the array


push(@x, 'DN', 'AL&ML', 'CS', 'SE');

# Printing the array


Malla Reddy Institute of Technology and Science (MRITS) 29
Scripting Language Lab Work Book

print "Updated array: @x";

Malla Reddy Institute of Technology and Science (MRITS) 30


Scripting Language Lab Work Book

Outputs:

Procedure:
1. Switch on the Computer and select the operating system
Linux/windows.
2. Open terminal or cmd and type perl –v and press enter then it gives
current version of perl.
3. Open the text editor or notepad and write the program and save as it
with extension ―.pl‖
4. Open the terminal or command prompt enter following commands:
i) cd\
ii) cd<space><path of the folder where the program file is saved>
5. Now run the program in terminal or command prompt using the
command: perl<space><filename.pl>
6. Note down the outputs and make a screenshot of them.
Scripting Language Lab Work Book

Result: Hence PERL script is written to implement the following list of


manipulating functions
a) Shift b)Unshift c) Push
.

Signature of the Faculty


Scripting Language Lab Work Book

PROGRAM-19
Substitution a word and Validating IP address
Objective: To write a Perl program to substitute a word, with another word
in a string.
b) To Write a Perl script to validate IP address and email address.

Tools Required:
1. PC
2. OS- Linux
3. Atom Text Editor
4. PERL version above 5.
Program a:
my $string = "Electronics and Computer Engineering";
$string =~ s/Computer/Communication/ig;
print $string;
Output:
Scripting Language Lab Work Book

Program b:
use strict;
use warnings;
use 5.010;
use Email::Valid;
foreach my $email ('[email protected]', ' [email protected] ', 'foo at bar.com')
{ my $address = Email::Valid->address($email);
say ($address ? "yes '$address'" : "no '$email'");
}
Output:

Procedure:
1. Switch on the Computer and select the operating system
Linux/windows.
2. Open terminal or cmd and type perl –v and press enter then it gives
current version of perl.
3. Open the text editor or notepad and write the program and save as it
with extension ―.pl‖
4. Open the terminal or command prompt enter following commands:
i) cd\
ii) cd<space><path of the folder where the program file is saved>
5. Now run the program in terminal or command prompt using the
command: perl<space><filename.pl>
6. Note down the outputs and make a screenshot of them.
Scripting Language Lab Work Book

Result: Hence PERL script is written to substitute a word and validation of


Email address.

Signature of the Faculty


Scripting Language Lab Work Book

PROGRAM-20
Print the file in reverse order
Objective: To write a Perl program to print the file in reverse order.

Tools Required:
5. PC
6. OS- Linux
7. Atom Text Editor
8. PERL version above 5.
Program:
@lines = <>; # Empty array to read the file from command prompt
print @lines, "\n"; # Printing the file
@revlines = scalar reverse("@lines"); # Reversing the file content
print @revlines, "\n"; # Printing the reverse content
Output:
Scripting Language Lab Work Book

Procedure:
7. Switch on the Computer and select the operating system
Linux/windows.
8. Open terminal or cmd and type perl –v and press enter then it gives
current version of perl.
9. Open the text editor or notepad and write the program and save as it
with extension ―.pl‖
10. Open the terminal or command prompt enter following commands:
i) cd\
ii) cd<space><path of the folder where the program file is saved>
11. Now run the program in terminal or command prompt using the
command: perl<space><filename.pl>
12. Note down the outputs and make a screenshot of them.

Result: Hence PERL script is written to reverse the content of the file.

Signature of the Faculty

You might also like