Perl: basic syntax reference, configuration file, template, Regular Expression

Source: Internet
Author: User

1. Basic syntax reference

Http://ind.ntou.edu.tw /~ Dada/cgi/perlsynx.htm

 

2. Configuration File

Http://www.itqun.net/content-detail/93521.html
Http://www.9php.com/FAQ/cxsjl/perl/2009/07/4285989147407.html
Http://blog.chinaunix.net/u/29291/showart_344126.html

[Test. pl]

  Use  Config  ::  Inifiles;
My $ Cfg = New config :: Inifiles ( - File => " Test. ini " , # Configuration File Name
- Allowcontinue => 1 , # Whether to run a parameter value in multiple rows
- Reloadwarn => 1 ,
- Nocase => 1 ); # Case Insensitive

@ Sect = $ Cfg -> Sections;
Print " @ Sect \ n " ;

$ A1 = $ Cfg -> Val ( " Section1 " , " A " );
$ B1 = $ Cfg -> Val ( " Section1 " , " B " );
Print " $ A1 $ B1 \ n " ;

$ A2 = $ Cfg -> Val ( " Section2 " , " A " );
$ B2 = $ Cfg -> Val ( " Section2 " , " B " );
@ B3 = $ Cfg -> Val ( " Section2 " , " B " );
Print " A2: $ A2 \ n \ nb2: $ B2 \ n \ nb3: @ B3 \ n " ;

[Test. INI]

   code highlighting produced by actipro codehighlighter (freeware) 
http://www.CodeHighlighter.com/
--> [ Section1 ]
A = 1
B = 2
[ section2 ]
A = Hello \
world
B = Hello
world
EOT

[Output]

 
  Section1 section2
1 2

A2: helloworld

B2: Hello
World

B3: Hello World

 

 

3. Template

Http://www.lupaworld.com/tutorial-view-aid-8885.html

[Test. pl]

  Print     & Template (  "  Test. Template  "  );

Sub Template {
Local ( * File ); # Filehandle
Local ( $ File ); # File Path
Local ( $ Html ); # HTML data

$ File = $ _ [ 0 ] | Die " Template: no template file specified \ n " ;

Open (File , " <$ File " ) | Die " Template: couldn't open $ file: $! \ N " ;
While ( < File > ){ $ Html . = $ _ ;}
Close (File );

@ Contents = QW (Xiao Zhang Xiaoming );

$ Html = ~ S /\ $ ( \ W + ) \ $ / $ Contents [$ 1 - 1 ] / G;

Return $ Html ;
}

[Test. TEMPLATE]

 
  $1 $ hello, I am$2$

[Output]

 
  Hello, James. I'm James.

 

4. Regular Expression

Http://www.chinaunix.net/jh/25/159388.html

9.1 three forms of Regular Expressions

First, we should know PerlProgramRegular expressions have three forms:

Match: M/<Regexp>;/(can also be abbreviated as/<Regexp>;/, skip m)

Replace: S/<pattern >;/ <replacement> ;/

Conversion: TR/<pattern>;/<replacemnt> ;/

This articleArticleThe regular expression syntax is also explained.

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.