Getting started with the Perl language

Source: Internet
Author: User
Tags perl interpreter perl script



Perl is an abbreviation for practical Extraction and report Language, which can be translated as a "utility statement extraction language".



Perl Syntax Basics:



(1) Perl programs consist of statements and statements



(2) Perl program execution from top to bottom



(3) The Perl statement ends with a semicolon (;), including statements such as circular judgments



(4) Perl does not have a strict format specification, it can be indented according to its preferred way



First Perl program:



(1) Interactive programming



Perl-e ' print ' Hellow, Wold "'



Use the-E option to execute Perl statements



(2) Script programming



The extension of a Perl script is a. pl or. pl and cannot contain spaces in the pin name



For example, write a simple script hello.pl as follows





 
 
1 #!/usr/bin/perl
2 
3 print "hello, wold";


The function of the code is to output the string "Hello, Wold", while #!/usr/bin/perl is the path to the Perl interpreter



Executing scripts in the terminal $perl hello.pl



Another way to execute a script is to have the script get executable permissions, chmod 0755 hello.pl (or chmod u+x hello.pl), and then./hello.pl Direct execution



Perl language Annotations:



(1) Single-line comment, #开头的行是注释行, will be ignored when executed



(2) Multi-line comments, beginning with =pod, =cut end, the middle part is the comment content, can be multiple lines, execution will be ignored. Perform the following example


1 #! / usr / bin / perl
  2 
  3 #This is a line of comments
  4
  5 = pod
  6 This is note 1
  7 This is note 2
  8 This is note 3
  9 = cut
10
11 print "hello, wold \ n";


White space in the Perl language:



(1) blank refers to space, blank line, tab, etc.



(2) The interpreter ignores the blank in the statement


 
print "hello, wold\n";
print              "hello, wold\n";
print
"hello, wold\n";


The above three pieces of code perform the same effect



Single and double quotation marks in the Perl language:



(1) Double quotes can parse some escape characters and variables normally



(2) Single quotes cannot be escaped


 
1 $a = 10;
2 print "a = $a\n";
3 print ‘b = $a\n‘;


The result of the output is:


 
1 a = 10
2 b = $a\n


Escaping in the Perl language:



(1) Perl relay uses backslashes \



Identifiers in the Perl language:



(1) Identifiers refer to the names of variables, constants, functions, and block of statements in a language



Getting started with the Perl language


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.