The ABC of Perl:my first Perl program

Source: Internet
Author: User
Tags perl interpreter learn perl

Hi everyone. Today I'll start a new series of esssays introducing the elementary knowledge of Perl, a computer language of which prob Ably many of us never heard. I ' ll try my best to articulate my idea. If There is something your disgree with, please feedback to me and I'll seriously consider your views.

I. What's Perl (practical Extraction and report Language)?

Just as C + +, Perl is Just another member of the Kingdom of computer language. Actually it ' s a kind of old-fashioned scripting language. There was a time, most Web applications were writen by Perl. Nowdays Perl is gradually taken place by Python and PHP partly because of its fecklessness, boundless flexbility and some Tricky grammars. However, those defects can not obscure its virtues. Perl have a powerful weapon---Regular Expression, which make this language extraordinary when text processing. Besides, Perl is also an object-oriented programming (OOP) language. Although it ' s not as efficient as C, you can simply write several lines of Perl code to implement some complicate function S, which'll largely shorten development cycles.

II. What does I need to know before learing Perl?

To be honest, it's not a good choice if your start with Perl when you know nothing about computer programing. In some ways Perl are over free, which may give the learner an illusion so you can write the code on any the. Unfortunately, there is still borders. If you ignore these limits, your code would crash and you even don ' t know what ' s wrong. You ' d better know something about C or Python or any other popular languages. And if you're familiar with Linux, you'll find it very easy to learn Perl regular expressions, because RE was actually an Enhanced version of awk/sed.

Iii. Reference Books

For a starter, the book ' Learning Perl ' was recommended, you can get a basic idea of Perl. If you want to go further, you can read ' programing Perl ' to learn some powerful tools. And if you want to know how Perl works, which means some fundamental operational mechanism, ' Advance Perl programing ' would Be right choice.

Iv. How to Setup Perl environment

For Windows, you can download and install ActivePerl, which is a integrated script interpreter. When you finish the installation, you can open the Cmd window and type "Perl-v", you'll see some information of Perl.

For Linux users, the normally Ubuntu system has integrated Perl interpreter. To check for so you can press Ctrl+alt+t to call out terminal and then type Perl-v.

V. Perl Editor:sublime Text

In fact, you can use anything to write Perl codes, as long as the suffix of the your file is '. pl ' or '. PM '. However sublime text would make the code writing more enjoyable. Now let me tell you how to use sublime text to write and run Perl codes.

First search and download sublime text, then install the software.

Just do as instruction, you can easily finish the installation.

The installation is finished. Now you can write your Perl codes by sublime. Note that the suffix of the file must is ". pl" or ". PM". However, you can not run your codes. To implement this function, you should move one more step.

Open Sublime text, you'll find option "Tools" in the toolbar. Click tools->build system->new Build System.

Then copy these codes into the new dialog box.

{    "cmd": ["Perl","- W","$file"],"File_regex":". * at (. *) line ([0-9]*)","selector":"Source.perl"}

Then press Ctrl+s, save the file with the name of ' Perl.sublime-build ' into the default directory. Done.

Now your sublime text was able to run Perl. (Use ctrl+b)

Vi. First Perl Program:hello World

Open Sublime, create a file saved as "hello.pl", type your code as follows:

# !/usr/bin/perl-wuse strict; Print " Hello world! " ; 1;

Then press CTRL+B, you'll get the results.

' # ' is a annotation for Perl, just as '/***/' for C language.

#!/usr/bin/perl-w is a linux-style sentence. #!/usr/bin/perl means that the system would find the Perl interpreter At/usr/bin/perl, for Windows users, this is dis  Pensable, but it's recommended to keep it's in consideration of portability. "-W" mean use waring mode, the interpreter would show some warning if your codes lack of standardization.

Use strict; means that the interpreter would use the most strict grammar to check your codes. It ' s better to add this line for novice.

1; Replaces the return-value of this program.

print ' Hello World ' means that the system print the sentence ' Hello World ' into the default output handle,the screens in O ther words.

Now there are already know how to write your first Perl program. Just try more for yourself!

 

The ABC of Perl:my first Perl program

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.