摘要: 不指定文件句柄给print,则默认会使用STDOUT。可以通过select 操作进行更改。 if(! open LOG, "> log.txt"){ die("error"); } select LOG; print "I hope Mr.Slate doesn't find out about this.\n";#将出错信息送到私有错误日志上if(! Open STDERR, “>>/home/barney/.error_log”){die “Can’t open error log for append: 阅读全文
posted @ 2012-09-10 20:59 nalasun 阅读(154) 评论(0) 推荐(0) 编辑
摘要: @backwards = reverse qw /yabba dabba doo /;$fred = @backwards; # 3($fred) = @backwards; # doo@betty = (); #将数组置空的正确方法@rocks = qw(talc quartz jade obsidian);print @rocks, "\n"; #talcquartzjadeobsidianprint scalar @rocks, "\n"; # 4<STDIN>在标量context 中返回输入的下一行。在列表context 中,它将返回 阅读全文
posted @ 2012-08-28 20:28 nalasun 阅读(156) 评论(0) 推荐(0) 编辑
摘要: 匹配FRED 时,也能匹配上fred, Fred,可以使用修饰符/i。点(.)不匹配换行符,这对于“单行中查找”的问题能很好解决。如果你的字符串中有换行符,那可以使用/s 这个修饰符。$_="I saw Barney\ndown at the bowling alley\nwith Fred\nlast night.\n";if(/Barney.*Fred/s){print "That string mentions Fred after Barney!\n";}else{print "No matched!"}/x 修饰符,允许你在 阅读全文
posted @ 2012-08-27 20:57 nalasun 阅读(145) 评论(0) 推荐(0) 编辑
摘要: 对于字符串比较,Perl 有如下的一些有趣的字符串比较符:lt le eq ge gt ne。(注意,在ASCII 中,大写字母在小写字母的前面)。相等= = eq不等!= ne小于< Lt大于> gt小于或等于<= le大于或等于>= ge$text = “a line of text\n”;chomp($text); #去掉换行符(\n)。chomp ($text = <STDIN>); #从键盘读入,去掉换行符正则表达式查看某个给定文件中是否某行提到过flint,同时同一行后面提到stone$grep‘flint.*stone’chapter*.txt 阅读全文
posted @ 2012-08-23 20:42 nalasun 阅读(219) 评论(0) 推荐(0) 编辑
摘要: printf:要输出数字,通常使用%g◆,它将根据需要自动选用浮点数,整数,或者指数。%d 为十进制◆整数,根据需要而截尾。%x 是针对十六进制的,%o 是针对八进制的。%s 是针对字符串的。 printf “%10s\n”, “wilma”; #输出为:○○○○○wilma 如果宽度值为负数,则为左对齐(对于所有的格式符) print “%-15s\n”, “flintstone”; #输出为flintstone○○○○Perl 自身有六个文件句柄:STDIN,STDOUT,STDERR,DATA,ARGV,ARGVOUT◆。$ ./your_program <dino >Wil 阅读全文
posted @ 2012-08-22 20:53 nalasun 阅读(235) 评论(0) 推荐(0) 编辑
摘要: 在while 循环中,Perl 读入一行,将它赋给变量,然后进入循环。再回到开头,读入下一行。但在foreach 循环中,由于行输入操作在列表的context 中使用,因为foreach 需要一个列表作为其参数。因此,它在循环执行前会将所有的输入读入。这种区别在读入一个400MB 的web 服务器的log 文件时非常明显。通常使用while 循环是一种更好的方法,因为它一次处理一行输入。$ ./my_program fred barney betty上述命令的含义是,运行my_program(在当前目录下),它将处理文件fred,再处理文件barney,最后是文件betty。如果没有命令行参数 阅读全文
posted @ 2012-08-21 21:00 nalasun 阅读(148) 评论(0) 推荐(0) 编辑
摘要: 如果你想知道更多的关于正则表达式的信息可以参看Jeffrey Friedl(O’Reily)的书籍《掌握正则表达式》(Mastering Regular Expessions)。 阅读全文
posted @ 2012-08-21 10:40 nalasun 阅读(93) 评论(0) 推荐(0) 编辑
摘要: Apt-GetTheapt-getcommand is a powerful command-line tool used to work with Ubuntu'sAdvanced Packaging Tool(APT) performing such functions as installation of new software packages, upgrade of existing software packages, updating of the package list index, and even upgrading the entire Ubuntu syst 阅读全文
posted @ 2012-03-15 15:47 nalasun 阅读(216) 评论(0) 推荐(0) 编辑
摘要: dpkgTo list all packages installed on the system, from a terminal prompt enter:dpkg -lDepending on the amount of packages on your system, this can generate a large amount of output. Pipe the output throughgrepto see if a specific package is installed:dpkg -l | grep apache2To list the files installed 阅读全文
posted @ 2012-03-15 15:35 nalasun 阅读(287) 评论(0) 推荐(0) 编辑
摘要: 人生并非“偶然”的连续,好事坏事交替而来才是人生。年轻的朋友们,你们代表将来的时代。遇到挫折时请不要颓丧,痛苦的时候要坚持奋斗,奋斗必有硕果,奋斗使你的人生更加多彩,使你的人格更加高尚。我们的心底有吸引灾难的磁石,它会从外界吸引刀枪、疾病、失业等等。--《生命之实相》回顾人生,我认为最重要的就是“永远持有明确的目标,并朝着这目标,孜孜不倦地努力、努力、再努力。”——稻盛和夫积极地对待人生。通常,企业经营都提倡描述5年、10年的发展规划。但是,我却注重“精力充沛地过好今天这一天”,只强调短期目标。为什么这样做?因为建立起长远规划,却无法落实,反而会让人灰心丧气,产生挫折感,引发负面的情绪和想法。 阅读全文
posted @ 2012-01-18 10:54 nalasun 阅读(531) 评论(0) 推荐(0) 编辑