Perl: 基本语法参考、配置文件、模板、正则表达式
2010-07-23 11:42
519 查看
1 基本语法参考
http://ind.ntou.edu.tw/~dada/cgi/Perlsynx.htm
2 配置文件
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】
【test.ini】
【输出】
3 模板
http://www.lupaworld.com/tutorial-view-aid-8885.html
【test.pl】
【test.template】
【输出】
4 正则表达式
http://www.chinaunix.net/jh/25/159388.html
9.1 正则表达式的三种形式
首先我们应该知道 Perl 程序中,正则表达式有三种存在形式,他们分别是:
匹配:m/<regexp>;/ (还可以简写为 /<regexp>;/ ,略去 m)
替换:s/<pattern>;/<replacement>;/
转化:tr/<pattern>;/<replacemnt>;/
这篇文章也讲解了正则表达式的语法。
http://ind.ntou.edu.tw/~dada/cgi/Perlsynx.htm
2 配置文件
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", #配置文件名 -allowcontinue => 1, #是否运行一个参数值写在多行 -reloadwarn => 1, -nocase => 1 ); #大小写不敏感 @sect = $cfg->Sections; print "@sect\n"; $a1 = $cfg->val("section1", "a"); $b1 = $cfg->val("section1", "b"); print "$a1 $b1\n\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\n";
【test.ini】
[section1] a=1 b=2 [section2] a=hello\ world b=<<EOT hello world EOT
【输出】
section1 section2 1 2 a2:helloworld b2:hello world b3:hello world
3 模板
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(小张 小明); $HTML =~ s/\$(\w+)\$/$contents[$1-1]/g; return $HTML; }
【test.template】
$1$你好,我是$2$
【输出】
小张你好,我是小明
4 正则表达式
http://www.chinaunix.net/jh/25/159388.html
9.1 正则表达式的三种形式
首先我们应该知道 Perl 程序中,正则表达式有三种存在形式,他们分别是:
匹配:m/<regexp>;/ (还可以简写为 /<regexp>;/ ,略去 m)
替换:s/<pattern>;/<replacement>;/
转化:tr/<pattern>;/<replacemnt>;/
这篇文章也讲解了正则表达式的语法。
相关文章推荐
- FreeMarker模板文件的组成及基本语法详解
- nginx的基本配置--配置文件语法和配置指令
- logback 参考官方文档 实现控制台与文件输出日志的 最基本配置
- Nginx配置文件基本应用参考手册
- FreeMarker模板文件的组成及基本语法详解(一)
- FreeMarker模板文件的组成及基本语法详解(二)
- FreeMarker模板文件的组成及基本语法详解
- FreeMarker基本语法详解及模板文件的组成(一)
- FreeMarker模板文件的组成及基本语法详解(二
- Nginx配置文件基本应用参考手册
- spring框架基本配置文件语法
- FreeMarker模板文件的组成及基本语法详解(一)
- hibernate 配置文件(hibernate.properties)基本模板
- FreeMarker模板文件的组成及基本语法详解(一)
- FreeMarker模板文件基本语法
- __PUBLIC__模板文件路径配置
- android studio gradle配置文件参考
- git忽略某些文件(.gitignore的配置语法)
- applicationContext.xml最基本配置文件
- 024-cxf.xml配置文件模板