Home Scripting Perl Tutorial Perl Definition
Main Menu
Home
System Verilog
Verilog
Methodologies
Open Vera
Digital Concepts
Verification Basics
Protocols
Scripting
    - Perl Tutorial
        -- Perl Definition
        -- Syntax & Variables
        -- strings
        -- Arrays
        -- Associative Arrays
        -- If & While Loop
        -- File Input
        -- Print Output
        -- Strings and Regular Expressions
        -- Subroutines
        -- Running External Programs
        -- References
        -- Terse Perl
    - Bash
    - Makefile Tutorial
    - Perl Examples
    - Bash Examples
Articles
Videos
Interview Questions
Computer Architechture
C and C++
Blog/Article
AsicGuru Blog
Tags Cloud
Ads
Usefull Sites
Know Your IP/Location
Local Information India
Buy Car/Inverter Batteries
Real Estate India
Sports Accessories India
What is Perl
Share This Articale:

1. What Is Perl?


Perl is a free, open source programming language created by Larry Wall. Perl aims for adjectives like "practical" and "quick" and not so much words like "structured" or "elegant". A culture has built up around Perl where people create and give away modules, documentation, sample code and a thousand other useful things .


Perl Niche

Perl is probably best known for text processing -- dealing with files, strings, and regular expressions. However, Perl's quick, informal style makes it attractive for all sorts of little programs. If I need a 23 line program to get some task done, I can write it in Perl and be done in 3 minutes.

Perl code is very portable -- I frequently move Perl programs back and forth from the Mac to various Unixes and it just works. With Perl, you are not locked in to any particular vendor or operating system. Perl code is also robust; Perl programs can have bugs, but they will not crash randomly like C or C++ programs. On the other hand, in my opinion, Perl's easy-going style makes it less appealing for large projects where I would rather use Java.

Running Perl

A Perl program is just a text file. You edit the text of your Perl program, and the Perl interpreter reads that text file directly to "run" it. This structure makes your edit-run-debug cycle nice and fast. On Unix, the Perl interpreter is called "perl" and you run a Perl program by running the Perl interpreter and telling it which file contains your Perl program...


> perl myprog.pl


The interpreter makes one pass of the file to analyze it and if there are no syntax or other  obvious errors, the interpreter runs the Perl code. There is no "main" function -- the interpreter just executes the statements in the file starting at the top. Following the Unix convention, the very first line in a Perl file usually looks like this...


#!/usr/bin/perl -w


This special line is a hint to Unix to use the Perl interpreter to execute the code in this file. The "-w" switch turns on warnings which is generally a good idea. In unix, use "chmod" to set the execute bit on a Perl file so it can be run right from the prompt...


> chmod u+x foo.pl

## set the "execute" bit for the file once
>

> foo.pl            ## automatically uses the perl interpreter to "run" this file

The second line in a Perl file is usually a "require" declaration that specifies what version of Perl the program expects...

#!/usr/bin/perl -w
require 5.004;

This Articles is written/submitted by puneet (Puneet Aggarwal). You can also contribute to Asicguru.com. Click here to start


Next >> Syntax & Variables

 
Login/Register
Register
Sign In
Login with :-
gmail-yahoo-twitter-facebook
| | |  
  •  
  • Bookmark
    ADS