Chinaunix首页 | 论坛 | 博客
  • 博客访问: 498450
  • 博文数量: 143
  • 博客积分: 4072
  • 博客等级: 上校
  • 技术积分: 1442
  • 用 户 组: 普通用户
  • 注册时间: 2007-02-20 19:27
文章分类

全部博文(143)

文章存档

2014年(2)

2011年(4)

2010年(1)

2009年(9)

2008年(34)

2007年(93)

我的朋友

分类:

2007-02-20 19:27:11

    MSN的blog经常出现登录不了的情况,决定全部搬到这里来了.今天做一下开篇说明,学习PERL是为LINUX下域文件管理,希望这几天有所收获。
    看了一点点PERL学习二十天,其中PERL学习的三个重要特点
1. I name variables and avoid using the implicit $_ or @_ variables whenever possible. (
2. I use subroutines to hold all code.
3. I use local variables and avoid globals whenever possible.
以下为个人补充
4. 在实际应用过程中, 不要用use diagnostics; 这样PERL会占用太量内存。
   如果一定调试,可以命令方式
   #] perl -Wdiagnostics scriptname
    个人认为warnings 也可以用替换方式调试
   #] perl -w scriptname
5. 不要使用带扩展名,如 filename.pl,以防日后切换成其它语言
 
   功能:
1、可以实现类似sed的替代
## replace FROM with TOX in all files FILESX, renaming originals with .bak 将FROM替换成TOX,同时还将原文件保留一份成.bak
% perl -p -i.bak -e "s/FROM/TOX/;" FILESX
## replace FROM with TOX in all files FILESX, overwriting originals 将所有FROM->TOX
% perl -p -i -e "s/FROM/TOX/;" FILESX
## Same as above, assumes FROM or TOX contain;ditto,只是/这里变成@
% perl -p -i -e "@;" FILESX
 
语句特点:
1、条件语句:0,“0”、“”这三个值为false,其它为true
2、执行语句必须是以{}包含,即使只一条语句。
3、语法:
    1)if 语句
if  ( conditionAAA ) {
...
} elsif ( conditionBBB ) {
...
} else {
...
}
   2)do ... while 语句
Finally, although the do { body } while (...) is legal Perl, it is not an actual loop construct in Perl.
Instead, it is the do statement with a while modifier. In particular, last and next will not work inside the body.
4、连接符 .与PHP一样
$i = 123;
print('i = $i\n'); # print: i = $i\n
print("i = $i\n"); # print: i = 123
print("i = $i+4\n"); # print: i = 123+4
print("i = " . ($i+4) . "\n"); # print: i = 127
print("i = " . $i+4 . "\n"); # print: 4 (may get warnings) 不解
print((("i = " . $i) + 4) . "\n"); # print: 4 (same as previous)
 
5、内建立变量 undef
The builtin value undef
represents this undefined value, much like NULL in C/C++, null in Java or nil in Lisp/Ada are undefined values.
 
6、操作符
 
 
书籍:
入门:
learning perl
要学习PERL的对象,可以考虑读如下两本书
 
Perl面向对象编程(Object-Oriented Perl)
高级Perl编程(第二版)
阅读(981) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~