Linux Scripts

How to run a perl script in ubuntu

Perl is an acronym, short for Practical Extraction and Report Language.

It was designed by Larry Wall as a tool for writing programs in the UNIX environment and is continually being updated and maintained by him. Like shell script languages, Perl does not require a special compiler and linker to turn the programs you write into working code. Instead, all you have to do is write the program and tell Perl to run it. This means that Perl is ideal for producing quick solutions to small programming problems, or for creating prototypes to test potential solutions to larger problems.

Perl is located in the ubuntu repositories, you can install it by the following command.

sudo apt-get install perl

perl is installed in usr/bin/

Writing your first perl program
#!/usr/bin/perl
#A simple perl program to print the user input print ("Hello, type in something\n");
$inputline=; print ($inputline);

..........................................................................
chmod +x scriptname.pl
............................................................................

 Open a terminal, cd to the directory where the script is located and run the script against perl. You may have to add the directory indicator in front of the script name:

#perl ./scriptname.pl

The "./" tells the perl interpreter that the script is located in this directory. You can try it without the "./" and it should work. Works for me no matter what version of Linux I use.

 

No comments:

Post a Comment