Getting Started
Introduction
Perl IDEs
History
Advice
Tools
Mini-Tutorial
Tutorial
Code Snippets

Resources
Top Sites
More Tutorials
Books
Magazines
Articles
NewsLetters
Mailing Lists
NewsGroups
Forums
User Groups
Talk Shows
Blogs
Clothing

GBIC >> Perl >> Introduction >> Simple Perl Script

Introduction to Perl - Simple Perl Script
Perl is a free programming language known for its ability to quickly manipulate text files. It is used extensively by programmers on PCs and UNIX machines to read, modify, and write text files and text-based databases.

More importantly, Perl has become the predominant server-based programming language for handling text-based web pages and is used to accept user inputs (usually from web page forms) and to use those inputs for real time database updates and to return custom web pages to users.

The following three sections provide additional introductory information about Perl.

Perl is free, easy to learn, and continues to evolve to meet the needs of web programmers.

A Simple Program
The tutorial section of this site contains information about writing Perl programs, but here's a quick look at a traditional "Hello World" program.

   #!/usr/bin/perl
   $name="Hello World";
   print $name;

And here's a line-by-line analysis of what the code does.

  • #!/usr/bin/perl
    Tells the operating system where the perl.exe program is located. The "#!" is just a key to identify the line as having the path information.

  • $name="Hello World";
    Assigns a value to a string variable.

  • print $name;
    Prints the string variable to the screen.

Executing a Perl Script on a PC
The Perl interpreter, the program that executes Perl scripts, is "perl.exe". To run the sample program above, save it to a file, such as "myscript.pl" then type in:

    perl myscript.pl

Any filename can be used but .pl and .cgi are extensions commonly used to indicate Perl scripts.