Perl Installation on Windows and write first program

Installation:
There are two methods (more specifically two distributions) to install Perl on Windows. One is using ActivePerl another is StrawberryPerl, you can choose either one of them. 

To install Active Perl: go to this link: http://www.activestate.com/activeperl and download the installation file, installation steps are self explanatory.

To install Strawberry Perl: go to this link: http://strawberryperl.com/ and download the 32 bit or 64 bit version depending on your system. Install the downloaded file.

Run the installer. Accept all the defaults and after a few minutes, Perl is installed. Check by opening up the command prompt and type perl -v command and press enter.

You should see a message indicating you have installed Perl correctly and are ready to write your first script.

Write and Run Your First Script
  1. You can write a Perl programs in a text editor. 
  2. Notepad, TextEdit, Vi, Emacs, Textmate, Ultra Edit and many other text editors can handle the job.
  3. Create a new text file and type the following exactly as shown:
#!usr/bin/perl

print "Enter your name: ";
$name=<STDIN>;
print "Hello, ${name} ... you will soon be a Perl addict!";

Save the file as hello.pl to a location of your choice. 

.pl extension is not mandatory, but it's good practice and helps you locate your Perl scripts easily.

Run Your Script
On the command prompt, change to the directory where you saved the Perl script. 
For example: 

cd c:\perl\scripts
Then type: perl hello.pl to run your script. 

If you typed everything exactly as shown, you are prompted to enter your name.

When you press the Enter key, Perl calls you by your name (in the example, it is Vinod) and give you a dire warning.

C:\Perl\scripts>perl hello.pl

Enter your name: Vinod

Hello, Vinod

... you will soon be a Perl addict!

Well done!
You have successfully installed Perl and written your first script. You might not understand the syntax you typed, but you'll understand it soon.


<-- Previous || Next -->

2 comments: