﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-Skynet-随笔分类-perl</title><link>http://www.blogjava.net/Skynet/category/37728.html</link><description /><language>zh-cn</language><lastBuildDate>Mon, 14 Dec 2009 13:17:17 GMT</lastBuildDate><pubDate>Mon, 14 Dec 2009 13:17:17 GMT</pubDate><ttl>60</ttl><item><title>shell txt 分析小结</title><link>http://www.blogjava.net/Skynet/archive/2009/11/26/303750.html</link><dc:creator>刘凯毅</dc:creator><author>刘凯毅</author><pubDate>Thu, 26 Nov 2009 03:27:00 GMT</pubDate><guid>http://www.blogjava.net/Skynet/archive/2009/11/26/303750.html</guid><wfw:comment>http://www.blogjava.net/Skynet/comments/303750.html</wfw:comment><comments>http://www.blogjava.net/Skynet/archive/2009/11/26/303750.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/Skynet/comments/commentRss/303750.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Skynet/services/trackbacks/303750.html</trackback:ping><description><![CDATA[<br />
<br />
<br />
<br />

<div style="width:425px;text-align:left" id="__ss_2587122"><a style="font:14px Helvetica,Arial,Sans-serif;display:block;margin:12px 0 3px 0;text-decoration:underline;" href="http://www.slideshare.net/liukaiyi/shell-2587122" title="Shell脚本">Shell脚本</a><object style="margin:0px" width="425" height="355"><param name="movie" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=shell-091125211831-phpapp02&stripped_title=shell-2587122" /><param name="allowFullScreen" value="true"/><param name="allowScriptAccess" value="always"/><embed src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=shell-091125211831-phpapp02&stripped_title=shell-2587122" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="355"></embed></object><div style="font-size:11px;font-family:tahoma,arial;height:26px;padding-top:2px;">View more <a style="text-decoration:underline;" href="http://www.slideshare.net/">presentations</a> from <a style="text-decoration:underline;" href="http://www.slideshare.net/liukaiyi">liukaiyi</a>.</div></div>
<img src ="http://www.blogjava.net/Skynet/aggbug/303750.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/Skynet/" target="_blank">刘凯毅</a> 2009-11-26 11:27 <a href="http://www.blogjava.net/Skynet/archive/2009/11/26/303750.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>perl 使用小结</title><link>http://www.blogjava.net/Skynet/archive/2009/11/11/301957.html</link><dc:creator>刘凯毅</dc:creator><author>刘凯毅</author><pubDate>Wed, 11 Nov 2009 05:36:00 GMT</pubDate><guid>http://www.blogjava.net/Skynet/archive/2009/11/11/301957.html</guid><wfw:comment>http://www.blogjava.net/Skynet/comments/301957.html</wfw:comment><comments>http://www.blogjava.net/Skynet/archive/2009/11/11/301957.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/Skynet/comments/commentRss/301957.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Skynet/services/trackbacks/301957.html</trackback:ping><description><![CDATA[<div style="border: 1px solid #cccccc; padding: 4px 5px 4px 4px; background-color: #eeeeee; font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: #000000;"><br />
<br />
<br />
<br />
环境设置：如果有系统字符编码&nbsp;冲突，在当前<br />
vim&nbsp;</span><span style="color: #000000;">~/.</span><span style="color: #000000;">bash_profile&nbsp;下加入<br />
LANG</span><span style="color: #000000;">=</span><span style="color: #000000;">zh_CN<br />
LC_ALL</span><span style="color: #000000;">=</span><span style="color: #000000;">zh_CN</span><span style="color: #000000;">.</span><span style="color: #000000;">UTF8<br />
export&nbsp;LANG&nbsp;LC_ALL<br />
<br />
<br />
字符编码转化</span><span style="color: #000000;">:</span><span style="color: #000000;"><br />
&nbsp;&nbsp;</span><span style="color: #008000;">#</span><span style="color: #008000;">&nbsp;由decode解析,默认会使用&nbsp;系统编码&nbsp;输出<br />
&nbsp;&nbsp;#&nbsp;在&nbsp;linux&nbsp;下面其实等价&nbsp;encode("UTF-8",&nbsp;decode("GBK",$_));</span><span style="color: #008000;"><br />
</span><span style="color: #000000;">perl&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">MEncode&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">ne&nbsp;</span><span style="color: #000000; font-weight: bold;">'</span><span style="color: #000000; font-weight: bold;">print&nbsp;decode("GBK",$_);</span><span style="color: #000000; font-weight: bold;">'</span><span style="color: #000000;">&nbsp;&nbsp;file</span><span style="color: #000000;">.</span><span style="color: #000000;">txt<br />
<br />
判断数据是否符合输出：<br />
&nbsp;&nbsp;echo&nbsp;</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000; font-weight: bold;">121</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">|</span><span style="color: #000000;">perl&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">ne&nbsp;</span><span style="color: #000000; font-weight: bold;">'</span><span style="color: #000000; font-weight: bold;">print&nbsp;if&nbsp;/2/;</span><span style="color: #000000; font-weight: bold;">'</span><span style="color: #000000;">&nbsp;&nbsp;&nbsp;</span><span style="color: #008000;">#</span><span style="color: #008000;">print&nbsp;123</span><span style="color: #008000;"><br />
</span><span style="color: #000000;"><br />
匹配正则group输出</span><span style="color: #000000;">:</span><span style="color: #000000;"><br />
&nbsp;&nbsp;echo&nbsp;</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000; font-weight: bold;">abc121a</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">|</span><span style="color: #000000;">perl&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">ne&nbsp;</span><span style="color: #000000; font-weight: bold;">'</span><span style="color: #000000; font-weight: bold;">print&nbsp;$1&nbsp;if&nbsp;/(\D+)/;</span><span style="color: #000000; font-weight: bold;">'</span><span style="color: #000000;">&nbsp;&nbsp;&nbsp;</span><span style="color: #008000;">#</span><span style="color: #008000;">print&nbsp;abc</span><span style="color: #008000;"><br />
</span><span style="color: #000000;"><br />
大小写转化：<br />
&nbsp;&nbsp;</span><span style="color: #008000;">#</span><span style="color: #008000;">&nbsp;全部&nbsp;大小转小写</span><span style="color: #008000;"><br />
</span><span style="color: #000000;">&nbsp;&nbsp;echo&nbsp;</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000; font-weight: bold;">ABC1C2cGJ</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">|</span><span style="color: #000000;">perl&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">ne&nbsp;</span><span style="color: #000000; font-weight: bold;">'</span><span style="color: #000000; font-weight: bold;">tr/[A-Z]/[a-z]/;&nbsp;print&nbsp;;</span><span style="color: #000000; font-weight: bold;">'</span><span style="color: #000000;">&nbsp;&nbsp;</span><span style="color: #008000;">#</span><span style="color: #008000;">print<br />
&nbsp;&nbsp;#&nbsp;"L&nbsp;中间全部小写&nbsp;"E&nbsp;&nbsp;&nbsp;;&nbsp;"U&nbsp;中间全部大写&nbsp;"E&nbsp;&nbsp;&nbsp;&nbsp;&#8595;</span><span style="color: #008000;"><br />
</span><span style="color: #000000;">&nbsp;&nbsp;echo&nbsp;</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000; font-weight: bold;">ABC1C2cGJ</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">|</span><span style="color: #000000;">perl&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">ne&nbsp;</span><span style="color: #000000; font-weight: bold;">'</span><span style="color: #000000; font-weight: bold;">s/(.*?1)(.*?)(2.*?)/$1\L$2\E$3/g;&nbsp;print&nbsp;;</span><span style="color: #000000; font-weight: bold;">'</span><span style="color: #000000;">&nbsp;&nbsp;</span><span style="color: #008000;">#</span><span style="color: #008000;">print&nbsp;ABC1c2cGJ</span><span style="color: #008000;"><br />
</span><span style="color: #000000;"><br />
<br />
<br />
源文件替换：<br />
&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000; font-weight: bold;">ABC&nbsp;123</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">&gt;</span><span style="color: #000000;">&nbsp;te<br />
&nbsp;&nbsp;&nbsp;sed&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">i&nbsp;</span><span style="color: #000000; font-weight: bold;">'</span><span style="color: #000000; font-weight: bold;">s/ABC/abc/g</span><span style="color: #000000; font-weight: bold;">'</span><span style="color: #000000;">&nbsp;te<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;或者&nbsp;</span><span style="color: #000000;">:</span><span style="color: #000000;">&nbsp;perl&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">i&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">pe&nbsp;</span><span style="color: #000000; font-weight: bold;">'</span><span style="color: #000000; font-weight: bold;">s/ABC/abc/g</span><span style="color: #000000; font-weight: bold;">'</span><span style="color: #000000;">&nbsp;te<br />
&nbsp;&nbsp;&nbsp;cat&nbsp;te&nbsp;</span><span style="color: #008000;">#</span><span style="color: #008000;">&nbsp;print&nbsp;abc&nbsp;123</span><span style="color: #008000;"><br />
</span><span style="color: #000000;"><br />
<br />
外部传参</span><span style="color: #000000;">:</span><span style="color: #000000;"><br />
&nbsp; </span>tt="cc"<br />
&nbsp; echo "gg" |perl -ne ' print "'$tt'" ;'<br />
&nbsp; 输出：cc<br />
<br />
<span style="color: #000000;">
&nbsp;&nbsp;perl&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">e&nbsp;&nbsp;</span><span style="color: #000000; font-weight: bold;">'</span><span style="color: #000000; font-weight: bold;">print&nbsp;"$ARGV[0]\t$ARGV[1]\n"&nbsp;</span><span style="color: #000000; font-weight: bold;">'</span><span style="color: #000000;">&nbsp;&nbsp;</span><span style="color: #000000; font-weight: bold;">'</span><span style="color: #000000; font-weight: bold;">par1</span><span style="color: #000000; font-weight: bold;">'</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000; font-weight: bold;">'</span><span style="color: #000000; font-weight: bold;">par2</span><span style="color: #000000; font-weight: bold;">'</span><span style="color: #000000;">&nbsp;&nbsp;</span><span style="color: #008000;">#</span><span style="color: #008000;">print&nbsp;par1&nbsp;par2</span><span style="color: #008000;"><br />
&nbsp; </span><span style="color: #000000;"><br />
<br />
重复列输出</span><span style="color: #000000;">:</span><span style="color: #000000;"><br />
&nbsp;&nbsp;&nbsp;cat&nbsp;xx</span><span style="color: #000000;">.</span><span style="color: #000000;">txt&nbsp;</span><span style="color: #000000;">|</span><span style="color: #000000;">&nbsp;awk&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">F</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000; font-weight: bold;">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000; font-weight: bold;">'</span><span style="color: #000000; font-weight: bold;">a[$1]++</span><span style="color: #000000; font-weight: bold;">'</span><span style="color: #000000;"><br />
&nbsp;&nbsp;&nbsp;或者&nbsp;</span><span style="color: #000000;">:</span><span style="color: #000000;">&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;cat&nbsp;xx</span><span style="color: #000000;">.</span><span style="color: #000000;">txt&nbsp;</span><span style="color: #000000;">|</span><span style="color: #000000;">perl&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">F</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000; font-weight: bold;">\t</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">ane&nbsp;&nbsp;</span><span style="color: #000000; font-weight: bold;">'</span><span style="color: #000000; font-weight: bold;">$a{$F[1]}++;END{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;while(($k,$v)=each(%a)){&nbsp;print&nbsp;"$k&nbsp;=&nbsp;$v&nbsp;"n";&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;}</span><span style="color: #000000; font-weight: bold;">'</span><span style="color: #000000;"><br />
&nbsp;&nbsp;&nbsp;&nbsp;结果比如：<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;百度手机在线&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;</span><span style="color: #800000;">7</span><span style="color: #000000;"><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;中兴&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;</span><span style="color: #800000;">2</span><span style="color: #000000;"><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;万信恒通&nbsp;&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;</span><span style="color: #800000;">2</span><span style="color: #000000;"><br />
&nbsp;&nbsp;&nbsp;还比如：查看各用户&nbsp;有多少个进程<br />
&nbsp;&nbsp;&nbsp;ps&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">ef&nbsp;</span><span style="color: #000000;">|</span><span style="color: #000000;">perl&nbsp;&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">ane&nbsp;&nbsp;</span><span style="color: #000000; font-weight: bold;">'</span><span style="color: #000000; font-weight: bold;">$a{$F[0]}++;END{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;while(($k,$v)=each(%a)){&nbsp;print&nbsp;"$k&nbsp;=&nbsp;$v \n";&nbsp;}<br />
&nbsp;&nbsp;&nbsp;}</span><span style="color: #000000; font-weight: bold;">'</span><span style="color: #000000;"><br />
<br />
求&nbsp;两项&nbsp;&nbsp;交集<br />
cat&nbsp;BuyMusic</span><span style="color: #000000;">.</span><span style="color: #800000;">20090525</span><span style="color: #000000;">|</span><span style="color: #000000;">&nbsp;perl&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">ne&nbsp;</span><span style="color: #000000; font-weight: bold;">'</span><span style="color: #000000; font-weight: bold;">BEGIN{<br />
&nbsp;$p1="600902000005416300";<br />
&nbsp;$p2="600902000006211983";<br />
&nbsp;$p_col=30;<br />
&nbsp;$mob_col=0;<br />
<br />
}END{<br />
&nbsp;&nbsp;my&nbsp;@inter&nbsp;=&nbsp;grep&nbsp;{$a{$_}}&nbsp;keys&nbsp;%b;&nbsp;#&nbsp;求交集<br />
&nbsp;&nbsp;#print&nbsp;$p1,"=",join(",",keys&nbsp;%a),""n";<br />
&nbsp;&nbsp;#print&nbsp;$p2,"=",join(",",keys&nbsp;%b),""n";<br />
&nbsp;&nbsp;print&nbsp;"产品&nbsp;$p1:",scalar&nbsp;keys&nbsp;%a,"&nbsp;"n";<br />
&nbsp;&nbsp;print&nbsp;"产品&nbsp;$p2:",scalar&nbsp;keys&nbsp;%b,"&nbsp;"n";<br />
&nbsp;&nbsp;print&nbsp;"交集:",scalar&nbsp;@inter,"&nbsp;"n";<br />
}<br />
chomp;<br />
@lis=split&nbsp;/\|&lt;&gt;\|/&nbsp;;<br />
if(&nbsp;$lis[&nbsp;$p_col]&nbsp;eq&nbsp;$p1&nbsp;){<br />
&nbsp;&nbsp;&nbsp;$a{$lis[$mob_col]}++;<br />
}<br />
if(&nbsp;$lis[$p_col]&nbsp;eq&nbsp;$p2&nbsp;){<br />
&nbsp;&nbsp;&nbsp;$b{$lis[$mob_col]}++;<br />
}<br />
</span><span style="color: #000000; font-weight: bold;">'</span><span style="color: #000000;"><br />
<br />
&nbsp;<br />
<br />
关键字&nbsp;Top&nbsp;</span><span style="color: #800000;">10</span><span style="color: #000000;">&nbsp;，输出源文本数据&nbsp;</span><span style="color: #000000;">:</span><span style="color: #000000;"><br />
perl&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">e&nbsp;&nbsp;</span><span style="color: #000000; font-weight: bold;">'</span><span style="color: #000000; font-weight: bold;"><br />
&nbsp;&nbsp;my&nbsp;$num=10;&nbsp;#&nbsp;top&nbsp;10<br />
&nbsp;&nbsp;open(MYFILE,&nbsp;"&lt;$ARGV[0]");<br />
&nbsp;&nbsp;open(MYFILE2,&nbsp;"&lt;$ARGV[0]");<br />
<br />
&nbsp;&nbsp;#&nbsp;关键字列数<br />
&nbsp;&nbsp;while(&lt;MYFILE&gt;){@lis=split&nbsp;/\|&lt;&gt;\|/;$fck{$lis[1]}++&nbsp;}<br />
<br />
&nbsp;&nbsp;foreach&nbsp;$k&nbsp;(sort&nbsp;{&nbsp;$fck{$b}&nbsp;&lt;=&gt;&nbsp;$fck{$a}&nbsp;}&nbsp;keys&nbsp;%fck){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(++$row&gt;$num){last;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$arr[@arr]&nbsp;=&nbsp;$k;<br />
&nbsp;&nbsp;}<br />
&nbsp;<br />
&nbsp;&nbsp;while(&lt;MYFILE2&gt;){@lis=split&nbsp;/\|&lt;&gt;\|/;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(grep&nbsp;{&nbsp;$arr[$_]&nbsp;eq&nbsp;$lis[1]&nbsp;}&nbsp;0..$#arr){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;print&nbsp;"$fck{$lis[1]}:$_";&nbsp;#带&nbsp;关键字出现次数输出<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print&nbsp;;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;}<br />
</span><span style="color: #000000; font-weight: bold;">'</span><span style="color: #000000;">&nbsp;qdSearch</span><span style="color: #000000;">.</span><span style="color: #0000ff;">log</span><span style="color: #000000;"><br />
<br />
<br />
<br />
<br />
</span></div>
<img src ="http://www.blogjava.net/Skynet/aggbug/301957.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/Skynet/" target="_blank">刘凯毅</a> 2009-11-11 13:36 <a href="http://www.blogjava.net/Skynet/archive/2009/11/11/301957.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>hadoop streaming( hadoop + perl  )小试</title><link>http://www.blogjava.net/Skynet/archive/2009/09/25/296420.html</link><dc:creator>刘凯毅</dc:creator><author>刘凯毅</author><pubDate>Fri, 25 Sep 2009 06:33:00 GMT</pubDate><guid>http://www.blogjava.net/Skynet/archive/2009/09/25/296420.html</guid><wfw:comment>http://www.blogjava.net/Skynet/comments/296420.html</wfw:comment><comments>http://www.blogjava.net/Skynet/archive/2009/09/25/296420.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/Skynet/comments/commentRss/296420.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Skynet/services/trackbacks/296420.html</trackback:ping><description><![CDATA[参考:<br />
&nbsp; http://hadoop.apache.org/common/docs/r0.15.2/streaming.html<br />
<br />
注意<br />
&nbsp; 目前 streaming 对 linux pipe #也就是 cat |wc -l 这样的管道 不支持，但不妨碍我们使用perl,python 行式命令！！<br />
&nbsp; 原话是 ：<br />
&nbsp; Can I use UNIX pipes? For example, will -mapper "cut -f1 | sed s/foo/bar/g" work?<br />
&nbsp;&nbsp;&nbsp; Currently this does not work and gives an "java.io.IOException: Broken
pipe" error. <br />
&nbsp;&nbsp;&nbsp; This is probably a bug that needs to be investigated.
<br />
&nbsp; 但如果你是强烈的 linux shell pipe 发烧友 ！ 参考下面<br />
&nbsp; $&gt; perl -e 'open( my $fh, "grep -v null <strong>tt </strong>|sed -n 1,5p |");while ( &lt;$fh&gt; ) {print;} '<br />
&nbsp;&nbsp;&nbsp;&nbsp;<strong> #不过我没测试通过 ！！ </strong><br />
<br />
环境 ：hadoop-0.18.3<br />
$&gt; find . -type f -name "*streaming*.jar" <br />
./contrib/streaming/hadoop-0.18.3-streaming.jar<br />
<br />
<br />
测试数据：<br />
<div style="border: 1px solid #cccccc; padding: 4px 5px 4px 4px; background-color: #eeeeee; font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: #808080;">-</span><span style="color: #000000;">bash</span><span style="color: #808080;">-</span><span style="color: #800000; font-weight: bold;">3.00</span><span style="color: #000000;">$&nbsp;head&nbsp;tt&nbsp;<br />
</span><span style="color: #0000ff;">null</span><span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;false&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #800000; font-weight: bold;">3702</span><span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #800000; font-weight: bold;">208100</span><span style="color: #000000;"><br />
</span><span style="color: #800000; font-weight: bold;">6005100</span><span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;false&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #800000; font-weight: bold;">70</span><span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #800000; font-weight: bold;">13220</span><span style="color: #000000;"><br />
</span><span style="color: #800000; font-weight: bold;">6005127</span><span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;false&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #800000; font-weight: bold;">24</span><span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #800000; font-weight: bold;">4640</span><span style="color: #000000;"><br />
</span><span style="color: #800000; font-weight: bold;">6005160</span><span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;false&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #800000; font-weight: bold;">25</span><span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #800000; font-weight: bold;">4820</span><span style="color: #000000;"><br />
</span><span style="color: #800000; font-weight: bold;">6005161</span><span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;false&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #800000; font-weight: bold;">20</span><span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #800000; font-weight: bold;">3620</span><span style="color: #000000;"><br />
</span><span style="color: #800000; font-weight: bold;">6005164</span><span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;false&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #800000; font-weight: bold;">14</span><span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #800000; font-weight: bold;">1280</span><span style="color: #000000;"><br />
</span><span style="color: #800000; font-weight: bold;">6005165</span><span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;false&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #800000; font-weight: bold;">37</span><span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #800000; font-weight: bold;">7080</span><span style="color: #000000;"><br />
</span><span style="color: #800000; font-weight: bold;">6005168</span><span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;false&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #800000; font-weight: bold;">104</span><span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #800000; font-weight: bold;">20140</span><span style="color: #000000;"><br />
</span><span style="color: #800000; font-weight: bold;">6005169</span><span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;false&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #800000; font-weight: bold;">35</span><span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #800000; font-weight: bold;">6680</span><span style="color: #000000;"><br />
</span><span style="color: #800000; font-weight: bold;">6005240</span><span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;false&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #800000; font-weight: bold;">169</span><span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #800000; font-weight: bold;">32140<br />
......<br />
</span></div>
<br />
<br />
运行：<br />
<div style="border: 1px solid #cccccc; padding: 4px 5px 4px 4px; background-color: #eeeeee; font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: #000000;">c1</span><span style="color: #000000;">=</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000; font-weight: bold;">&nbsp; perl&nbsp;-ne&nbsp;&nbsp;'if(/.*</span><span style="color: #000000; font-weight: bold;">\</span><span style="color: #000000;">t(</span><span style="color: #000000;">.*</span><span style="color: #000000;">)</span><span style="color: #000000;">/</span><span style="color: #000000;">){</span><span style="color: #000000; font-weight: bold;">\</span><span style="color: #000000; font-weight: bold;">$sum+=</span><span style="color: #000000; font-weight: bold;">\</span><span style="color: #000000;">$</span><span style="color: #800000;">1</span><span style="color: #000000;">;}END{</span><span style="color: #0000ff;">print</span><span style="color: #000000;"> <strong>\"</strong></span><span style="color: #000000; font-weight: bold;">\</span><span style="color: #000000; font-weight: bold;">$sum\";}'</span><span style="color: #000000; font-weight: bold;">&nbsp; "<br />
# 注意 这里 $ 要写成 \$&nbsp;&nbsp;&nbsp; " 写成 \"<br />
</span><span style="color: #000000;">
echo $c1; # 打印输出&nbsp; </span>perl -ne 'if(/.*"t(.*)/){$sum+=$1;}END{print $sum;}'<br />
<span style="color: #000000;">hadoop&nbsp;jar&nbsp;hadoop</span><span style="color: #000000;">-</span><span style="color: #800000;">0.18</span><span style="color: #000000;">.</span><span style="color: #800000;">3</span><span style="color: #000000;">-</span><span style="color: #000000;">streaming</span><span style="color: #000000;">.</span><span style="color: #000000;">jar <br />
&nbsp;&nbsp; </span><span style="color: #000000;">-</span><span style="color: #000000;">input&nbsp;file</span><span style="color: #000000;">:///</span><span style="color: #000000;">data</span><span style="color: #000000;">/</span><span style="color: #000000;">hadoop</span><span style="color: #000000;">/</span><span style="color: #000000;">lky</span><span style="color: #000000;">/</span><span style="color: #000000;">jar</span><span style="color: #000000;">/</span><span style="color: #000000;">tt&nbsp; </span><span style="color: #000000;"><br />
&nbsp;&nbsp; -</span><span style="color: #000000;">mapper&nbsp;&nbsp;&nbsp;</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000; font-weight: bold;">/bin/cat</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000;">&nbsp; </span><span style="color: #000000;"><br />
&nbsp;&nbsp; -</span><span style="color: #000000;">reducer&nbsp;</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000; font-weight: bold;">$c1</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000;">&nbsp; <br />
&nbsp;&nbsp; </span><span style="color: #000000;">-</span><span style="color: #000000;">output&nbsp;file</span><span style="color: #000000;">:///</span><span style="color: #000000;">tmp</span><span style="color: #000000;">/</span><span style="color: #000000;">lky</span><span style="color: #000000;">/</span><span style="color: #000000;">streamingx8</span></div>
<br />
<br />
结果:<br />
cat <span style="color: #000000;">/</span><span style="color: #000000;">tmp</span><span style="color: #000000;">/</span><span style="color: #000000;">lky</span><span style="color: #000000;">/</span><span style="color: #000000;">streamingx8/*<br />
</span>1166480<br />
<br />
本地运行输出:<br />
perl -ne 'if(/.*"t(.*)/){$sum+=$1;}END{print $sum;}' &lt; tt<br />
1166480<br />
<br />
结果正确!!!!<br />
<br />
<br />
命令自带文档：<br />
<div style="border: 1px solid #cccccc; padding: 4px 5px 4px 4px; background-color: #eeeeee; font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: #000000;">-</span><span style="color: #000000;">bash</span><span style="color: #000000;">-</span><span style="color: #000000;">3.00</span><span style="color: #000000;">$&nbsp;hadoop&nbsp;jar&nbsp;hadoop</span><span style="color: #000000;">-</span><span style="color: #000000;">0.18</span><span style="color: #000000;">.</span><span style="color: #000000;">3</span><span style="color: #000000;">-</span><span style="color: #000000;">streaming.jar&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">info<br />
</span><span style="color: #000000;">09</span><span style="color: #000000;">/</span><span style="color: #000000;">09</span><span style="color: #000000;">/</span><span style="color: #000000;">25</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">14</span><span style="color: #000000;">:</span><span style="color: #000000;">50</span><span style="color: #000000;">:</span><span style="color: #000000;">12</span><span style="color: #000000;">&nbsp;ERROR&nbsp;streaming.StreamJob:&nbsp;Missing&nbsp;required&nbsp;option&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">input<br />
Usage:&nbsp;$HADOOP_HOME</span><span style="color: #000000;">/</span><span style="color: #000000;">bin</span><span style="color: #000000;">/</span><span style="color: #000000;">hadoop&nbsp;[</span><span style="color: #000000;">--</span><span style="color: #000000;">config&nbsp;dir]&nbsp;jar&nbsp;\<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$HADOOP_HOME</span><span style="color: #000000;">/</span><span style="color: #000000;">hadoop</span><span style="color: #000000;">-</span><span style="color: #000000;">streaming.jar&nbsp;[options]<br />
Options:<br />
&nbsp;&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">input&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">path</span><span style="color: #000000;">&gt;</span><span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DFS&nbsp;input&nbsp;file(s)&nbsp;</span><span style="color: #0000ff;">for</span><span style="color: #000000;">&nbsp;the&nbsp;Map&nbsp;step<br />
&nbsp;&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">output&nbsp;&nbsp;&nbsp;</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">path</span><span style="color: #000000;">&gt;</span><span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DFS&nbsp;output&nbsp;directory&nbsp;</span><span style="color: #0000ff;">for</span><span style="color: #000000;">&nbsp;the&nbsp;Reduce&nbsp;step<br />
&nbsp;&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">mapper&nbsp;&nbsp;&nbsp;</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">cmd</span><span style="color: #000000;">|</span><span style="color: #000000;">JavaClassName</span><span style="color: #000000;">&gt;</span><span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;The&nbsp;streaming&nbsp;command&nbsp;to&nbsp;run<br />
&nbsp;&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">combiner&nbsp;</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">JavaClassName</span><span style="color: #000000;">&gt;</span><span style="color: #000000;">&nbsp;Combiner&nbsp;has&nbsp;to&nbsp;be&nbsp;a&nbsp;Java&nbsp;</span><span style="color: #0000ff;">class</span><span style="color: #000000;"><br />
&nbsp;&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">reducer&nbsp;&nbsp;</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">cmd</span><span style="color: #000000;">|</span><span style="color: #000000;">JavaClassName</span><span style="color: #000000;">&gt;</span><span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;The&nbsp;streaming&nbsp;command&nbsp;to&nbsp;run<br />
&nbsp;&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">file&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">file</span><span style="color: #000000;">&gt;</span><span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;File</span><span style="color: #000000;">/</span><span style="color: #000000;">dir&nbsp;to&nbsp;be&nbsp;shipped&nbsp;</span><span style="color: #0000ff;">in</span><span style="color: #000000;">&nbsp;the&nbsp;Job&nbsp;jar&nbsp;file<br />
&nbsp;&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">dfs&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">h:p</span><span style="color: #000000;">&gt;|</span><span style="color: #000000;">local&nbsp;&nbsp;Optional.&nbsp;Override&nbsp;DFS&nbsp;configuration<br />
&nbsp;&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">jt&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">h:p</span><span style="color: #000000;">&gt;|</span><span style="color: #000000;">local&nbsp;&nbsp;Optional.&nbsp;Override&nbsp;JobTracker&nbsp;configuration<br />
&nbsp;&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">additionalconfspec&nbsp;specfile&nbsp;&nbsp;Optional.<br />
&nbsp;&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">inputformat&nbsp;TextInputFormat(</span><span style="color: #0000ff;">default</span><span style="color: #000000;">)</span><span style="color: #000000;">|</span><span style="color: #000000;">SequenceFileAsTextInputFormat</span><span style="color: #000000;">|</span><span style="color: #000000;">JavaClassName&nbsp;Optional.<br />
&nbsp;&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">outputformat&nbsp;TextOutputFormat(</span><span style="color: #0000ff;">default</span><span style="color: #000000;">)</span><span style="color: #000000;">|</span><span style="color: #000000;">JavaClassName&nbsp;&nbsp;Optional.<br />
&nbsp;&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">partitioner&nbsp;JavaClassName&nbsp;&nbsp;Optional.<br />
&nbsp;&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">numReduceTasks&nbsp;</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">num</span><span style="color: #000000;">&gt;</span><span style="color: #000000;">&nbsp;&nbsp;Optional.<br />
&nbsp;&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">inputreader&nbsp;</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">spec</span><span style="color: #000000;">&gt;</span><span style="color: #000000;">&nbsp;&nbsp;Optional.<br />
&nbsp;&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">jobconf&nbsp;&nbsp;</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">n</span><span style="color: #000000;">&gt;=&lt;</span><span style="color: #000000;">v</span><span style="color: #000000;">&gt;</span><span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;Optional.&nbsp;Add&nbsp;or&nbsp;</span><span style="color: #0000ff;">override</span><span style="color: #000000;">&nbsp;a&nbsp;JobConf&nbsp;property<br />
&nbsp;&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">cmdenv&nbsp;&nbsp;&nbsp;</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">n</span><span style="color: #000000;">&gt;=&lt;</span><span style="color: #000000;">v</span><span style="color: #000000;">&gt;</span><span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;Optional.&nbsp;Pass&nbsp;env.var&nbsp;to&nbsp;streaming&nbsp;commands<br />
&nbsp;&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">mapdebug&nbsp;</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">path</span><span style="color: #000000;">&gt;</span><span style="color: #000000;">&nbsp;&nbsp;Optional.&nbsp;To&nbsp;run&nbsp;</span><span style="color: #0000ff;">this</span><span style="color: #000000;">&nbsp;script&nbsp;when&nbsp;a&nbsp;map&nbsp;task&nbsp;fails&nbsp;<br />
&nbsp;&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">reducedebug&nbsp;</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">path</span><span style="color: #000000;">&gt;</span><span style="color: #000000;">&nbsp;&nbsp;Optional.&nbsp;To&nbsp;run&nbsp;</span><span style="color: #0000ff;">this</span><span style="color: #000000;">&nbsp;script&nbsp;when&nbsp;a&nbsp;reduce&nbsp;task&nbsp;fails&nbsp;<br />
&nbsp;&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">cacheFile&nbsp;fileNameURI<br />
&nbsp;&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">cacheArchive&nbsp;fileNameURI<br />
&nbsp;&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">verbose</span></div>
<br />
<br />
<img src ="http://www.blogjava.net/Skynet/aggbug/296420.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/Skynet/" target="_blank">刘凯毅</a> 2009-09-25 14:33 <a href="http://www.blogjava.net/Skynet/archive/2009/09/25/296420.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>部分高级正则特性 使用</title><link>http://www.blogjava.net/Skynet/archive/2009/08/27/292835.html</link><dc:creator>刘凯毅</dc:creator><author>刘凯毅</author><pubDate>Thu, 27 Aug 2009 08:04:00 GMT</pubDate><guid>http://www.blogjava.net/Skynet/archive/2009/08/27/292835.html</guid><wfw:comment>http://www.blogjava.net/Skynet/comments/292835.html</wfw:comment><comments>http://www.blogjava.net/Skynet/archive/2009/08/27/292835.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/Skynet/comments/commentRss/292835.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Skynet/services/trackbacks/292835.html</trackback:ping><description><![CDATA[<span style="color: rgb(0, 0, 0);">一些特殊正则元字符说明</span><span style="color: rgb(0, 0, 0);">:</span><span style="color: rgb(0, 0, 0);"><br />
&nbsp;
</span><span style="color: rgb(128, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">.</span>&nbsp;<span style="color: rgb(0, 0, 0);">*?</span><span style="color: rgb(0, 0, 0);">&nbsp;和&nbsp;</span><span style="color: rgb(0, 0, 0);">+?</span><span style="color: rgb(0, 0, 0);">&nbsp;和&nbsp;{n</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);">}</span><span style="color: rgb(0, 0, 0);">?</span><span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;懒惰匹配&nbsp;<br />
&nbsp;&nbsp;
</span><span style="color: rgb(128, 0, 0);">1.1</span><span style="color: rgb(0, 0, 0);">&nbsp;非懒惰&nbsp;　　　　　　　　　　　　　　　&nbsp;&nbsp; &#8595;<br />
&nbsp;&nbsp;&nbsp;
echo&nbsp;</span><span style="color: rgb(0, 0, 0); font-weight: bold;">"</span><span style="color: rgb(0, 0, 0); font-weight: bold;">ab2c121a</span><span style="color: rgb(0, 0, 0); font-weight: bold;">"</span>&nbsp;<span style="color: rgb(0, 0, 0);">|</span><span style="color: rgb(0, 0, 0);">perl&nbsp;</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">ne&nbsp;</span><span style="color: rgb(0, 0, 0); font-weight: bold;">'</span><span style="color: rgb(0, 0, 0); font-weight: bold;">print&nbsp;$1&nbsp;if&nbsp;/(.*)"d/;</span><span style="color: rgb(0, 0, 0); font-weight: bold;">'</span><span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 128, 0);">#</span><span style="color: rgb(0, 128, 0);">print&nbsp;ab2c12</span><span style="color: rgb(0, 128, 0);"><br />
&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(128, 0, 0);">1.2</span><span style="color: rgb(0, 0, 0);">&nbsp;懒惰&nbsp;　　　　　　　　　　　　　　　　&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8595;<br />
&nbsp;&nbsp;&nbsp;
echo&nbsp;</span><span style="color: rgb(0, 0, 0); font-weight: bold;">"</span><span style="color: rgb(0, 0, 0); font-weight: bold;">ab2c121a</span><span style="color: rgb(0, 0, 0); font-weight: bold;">"</span>&nbsp;<span style="color: rgb(0, 0, 0);">|</span><span style="color: rgb(0, 0, 0);">perl&nbsp;</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">ne&nbsp;</span><span style="color: rgb(0, 0, 0); font-weight: bold;">'</span><span style="color: rgb(0, 0, 0); font-weight: bold;">print&nbsp;$1&nbsp;if&nbsp;/(.*?)"d/;</span><span style="color: rgb(0, 0, 0); font-weight: bold;">'</span><span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 128, 0);">#</span><span style="color: rgb(0, 128, 0);">print&nbsp;ab</span><span style="color: rgb(0, 128, 0);"><br />
&nbsp;
</span><span style="color: rgb(128, 0, 0);">2</span><span style="color: rgb(0, 0, 0);">.</span><span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;回溯引用和前后查找</span><span style="color: rgb(0, 0, 0);">:</span><span style="color: rgb(0, 0, 0);"><br />
&nbsp;&nbsp;
</span><span style="color: rgb(128, 0, 0);">2.1</span><span style="color: rgb(0, 0, 0);">&nbsp;向前查找&nbsp;&nbsp;&nbsp;(</span><span style="color: rgb(0, 0, 0);">?=..</span><span style="color: rgb(0, 0, 0);">)&nbsp;&nbsp;&nbsp; 　　　　　　　　　　　　&nbsp;&nbsp; &#8595;<br />
&nbsp;&nbsp;&nbsp;
echo&nbsp;</span><span style="color: rgb(0, 0, 0); font-weight: bold;">"</span><span style="color: rgb(0, 0, 0); font-weight: bold;">ab2c121a</span><span style="color: rgb(0, 0, 0); font-weight: bold;">"</span>&nbsp;<span style="color: rgb(0, 0, 0);">|</span><span style="color: rgb(0, 0, 0);">perl&nbsp;</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">ne&nbsp;</span><span style="color: rgb(0, 0, 0); font-weight: bold;">'</span><span style="color: rgb(0, 0, 0); font-weight: bold;">print&nbsp;$1&nbsp;if&nbsp;/(.*?)(?=2)/;</span><span style="color: rgb(0, 0, 0); font-weight: bold;">'</span><span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;</span><span style="color: rgb(0, 128, 0);">#</span><span style="color: rgb(0, 128, 0);">print&nbsp;ab</span><span style="color: rgb(0, 128, 0);"><br />
&nbsp;&nbsp;
</span><span style="color: rgb(128, 0, 0);">2.2</span><span style="color: rgb(0, 0, 0);">&nbsp;向后查找&nbsp;(</span><span style="color: rgb(0, 0, 0);">?&lt;=..</span><span style="color: rgb(0, 0, 0);">)&nbsp;&nbsp;　&nbsp; 　&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;　　　　　　&#8595;<br />
&nbsp;&nbsp;&nbsp;
echo&nbsp;</span><span style="color: rgb(0, 0, 0); font-weight: bold;">"</span><span style="color: rgb(0, 0, 0); font-weight: bold;">ab2c121a</span><span style="color: rgb(0, 0, 0); font-weight: bold;">"</span>&nbsp;<span style="color: rgb(0, 0, 0);">|</span><span style="color: rgb(0, 0, 0);">perl&nbsp;</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">ne&nbsp;</span><span style="color: rgb(0, 0, 0); font-weight: bold;">'</span><span style="color: rgb(0, 0, 0); font-weight: bold;">print&nbsp;$1&nbsp;if&nbsp;/(?&lt;=2)(.*)(?=2)/;</span><span style="color: rgb(0, 0, 0); font-weight: bold;">'</span>&nbsp;<span style="color: rgb(0, 128, 0);">#</span><span style="color: rgb(0, 128, 0);">print&nbsp;c1</span><span style="color: rgb(0, 128, 0);"><br />
&nbsp;&nbsp;
</span><span style="color: rgb(128, 0, 0);">2.3</span><span style="color: rgb(0, 0, 0);">&nbsp;负向</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">前</span><span style="color: rgb(0, 0, 0);">/</span><span style="color: rgb(0, 0, 0);">后&nbsp;查找&nbsp;&nbsp;(</span><span style="color: rgb(0, 0, 0);">?!..</span><span style="color: rgb(0, 0, 0);">)&nbsp;(</span><span style="color: rgb(0, 0, 0);">?&lt;!..</span><span style="color: rgb(0, 0, 0);">)&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;
</span><span style="color: rgb(0, 128, 0);">#</span><span style="color: rgb(0, 128, 0);">不能匹配&nbsp;..&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8595;</span><span style="color: rgb(0, 128, 0);"><br />
&nbsp;&nbsp;&nbsp;
</span><span style="color: rgb(0, 0, 0);">echo&nbsp;</span><span style="color: rgb(0, 0, 0); font-weight: bold;">"</span><span style="color: rgb(0, 0, 0); font-weight: bold;">ab2c121a</span><span style="color: rgb(0, 0, 0); font-weight: bold;">"</span>&nbsp;<span style="color: rgb(0, 0, 0);">|</span><span style="color: rgb(0, 0, 0);">perl&nbsp;</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">ne&nbsp;</span><span style="color: rgb(0, 0, 0); font-weight: bold;">'</span><span style="color: rgb(0, 0, 0); font-weight: bold;">print&nbsp;$1&nbsp;if&nbsp;/(?&lt;!2)(c.*)/;</span><span style="color: rgb(0, 0, 0); font-weight: bold;">'</span><span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 128, 0);">#</span><span style="color: rgb(0, 128, 0);">print&nbsp;无</span><span style="color: rgb(0, 128, 0);"><br />
&nbsp;&nbsp;&nbsp;
</span><span style="color: rgb(0, 0, 0);">echo&nbsp;</span><span style="color: rgb(0, 0, 0); font-weight: bold;">"</span><span style="color: rgb(0, 0, 0); font-weight: bold;">ab2c121a</span><span style="color: rgb(0, 0, 0); font-weight: bold;">"</span>&nbsp;<span style="color: rgb(0, 0, 0);">|</span><span style="color: rgb(0, 0, 0);">perl&nbsp;</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">ne&nbsp;</span><span style="color: rgb(0, 0, 0); font-weight: bold;">'</span><span style="color: rgb(0, 0, 0); font-weight: bold;">print&nbsp;$1&nbsp;if&nbsp;/(?&lt;!3)(c.*)/;</span><span style="color: rgb(0, 0, 0); font-weight: bold;">'</span><span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 128, 0);">#</span><span style="color: rgb(0, 128, 0);">print&nbsp;c121a</span><span style="color: rgb(0, 128, 0);"><br />
&nbsp;&nbsp;
</span><span style="color: rgb(128, 0, 0);">2.4</span><span style="color: rgb(0, 0, 0);">&nbsp;条件&nbsp;</span><span style="color: rgb(0, 0, 0);">?</span><span style="color: rgb(0, 0, 0);">()&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span>&nbsp;<span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 0);">?</span><span style="color: rgb(0, 0, 0);">()</span><span style="color: rgb(0, 0, 0);">|</span>&nbsp;<span style="color: rgb(0, 0, 0);">=</span>&nbsp;<span style="color: rgb(0, 0, 255);">if</span>&nbsp;<span style="color: rgb(0, 0, 255);">else</span><span style="color: rgb(0, 0, 0);"><br />
&nbsp;&nbsp;&nbsp;
</span><span style="color: rgb(0, 128, 0);">#</span><span style="color: rgb(0, 128, 0);">&nbsp;?()&nbsp;&nbsp;例如&nbsp;&nbsp;&lt;p&gt;&nbsp;&lt;/p&gt;&nbsp;必须同时出现&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8595;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8595;&nbsp;&nbsp;</span><span style="color: rgb(0, 128, 0);"><br />
&nbsp;&nbsp;&nbsp;
</span><span style="color: rgb(0, 0, 0);">echo&nbsp;</span><span style="color: rgb(0, 0, 0); font-weight: bold;">"</span><span style="color: rgb(0, 0, 0); font-weight: bold;">&lt;p&gt;xx&lt;/p&gt;</span><span style="color: rgb(0, 0, 0); font-weight: bold;">"</span><span style="color: rgb(0, 0, 0);">|</span><span style="color: rgb(0, 0, 0);">perl&nbsp;</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">ne&nbsp;</span><span style="color: rgb(0, 0, 0); font-weight: bold;">'</span><span style="color: rgb(0, 0, 0); font-weight: bold;">print&nbsp;$2&nbsp;&nbsp;if&nbsp;/(&lt;p&gt;)?("w*)(?(1)&lt;"/p&gt;)/</span><span style="color: rgb(0, 0, 0); font-weight: bold;">'</span><span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 128, 0);">#</span><span style="color: rgb(0, 128, 0);">print&nbsp;&nbsp;xx</span><span style="color: rgb(0, 128, 0);"><br />
&nbsp;&nbsp;&nbsp;
</span><span style="color: rgb(0, 0, 0);">echo&nbsp;</span><span style="color: rgb(0, 0, 0); font-weight: bold;">"</span><span style="color: rgb(0, 0, 0); font-weight: bold;">&lt;p&gt;xx</span><span style="color: rgb(0, 0, 0); font-weight: bold;">"</span><span style="color: rgb(0, 0, 0);">|</span><span style="color: rgb(0, 0, 0);">perl&nbsp;</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">ne&nbsp;</span><span style="color: rgb(0, 0, 0); font-weight: bold;">'</span><span style="color: rgb(0, 0, 0); font-weight: bold;">print&nbsp;$2,""n"&nbsp;if&nbsp;/(&lt;p&gt;)?("w*)(?(1)&lt;"/p&gt;)/</span><span style="color: rgb(0, 0, 0); font-weight: bold;">'</span><span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 128, 0);">#</span><span style="color: rgb(0, 128, 0);">print&nbsp;空</span><span style="color: rgb(0, 128, 0);"><br />
&nbsp;&nbsp;&nbsp;
</span><span style="color: rgb(0, 0, 0);">echo&nbsp;</span><span style="color: rgb(0, 0, 0); font-weight: bold;">"</span><span style="color: rgb(0, 0, 0); font-weight: bold;">xx</span><span style="color: rgb(0, 0, 0); font-weight: bold;">"</span><span style="color: rgb(0, 0, 0);">|</span><span style="color: rgb(0, 0, 0);">perl&nbsp;</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">ne&nbsp;</span><span style="color: rgb(0, 0, 0); font-weight: bold;">'</span><span style="color: rgb(0, 0, 0); font-weight: bold;">print&nbsp;$2&nbsp;if&nbsp;/(&lt;p&gt;)?("w*)(?(1)&lt;"/p&gt;)/</span><span style="color: rgb(0, 0, 0); font-weight: bold;">'</span><span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 128, 0);">#</span><span style="color: rgb(0, 128, 0);">print&nbsp;xx<br />
&nbsp;&nbsp;&nbsp;
#&nbsp;?()|&nbsp;&nbsp;例如&nbsp;还是上面的，&nbsp;<br />
&nbsp;&nbsp;&nbsp;
#&nbsp;当&nbsp;有&lt;p&gt;&nbsp;可以接&lt;/p&gt;&nbsp;也可以接&nbsp;数字结尾&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8595;</span><span style="color: rgb(0, 0, 0);"><br />
echo&nbsp;</span><span style="color: rgb(0, 0, 0); font-weight: bold;">"</span><span style="color: rgb(0, 0, 0); font-weight: bold;">&lt;p&gt;xx1&lt;/p&gt;</span><span style="color: rgb(0, 0, 0); font-weight: bold;">"</span><span style="color: rgb(0, 0, 0);">|</span><span style="color: rgb(0, 0, 0);">perl&nbsp;</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">ne&nbsp;</span><span style="color: rgb(0, 0, 0); font-weight: bold;">'</span><span style="color: rgb(0, 0, 0); font-weight: bold;">print&nbsp;$2&nbsp;&nbsp;if&nbsp;/(&lt;p&gt;)?("w*)(?(1)&lt;"/p&gt;|"d)/</span><span style="color: rgb(0, 0, 0); font-weight: bold;">'</span><span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;</span><span style="color: rgb(0, 128, 0);">#</span><span style="color: rgb(0, 128, 0);">print&nbsp;xx1</span><span style="color: rgb(0, 0, 0);"><br />
echo&nbsp;</span><span style="color: rgb(0, 0, 0); font-weight: bold;">"</span><span style="color: rgb(0, 0, 0); font-weight: bold;">&lt;p&gt;xx1</span><span style="color: rgb(0, 0, 0); font-weight: bold;">"</span><span style="color: rgb(0, 0, 0);">|</span><span style="color: rgb(0, 0, 0);">perl&nbsp;</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">ne&nbsp;</span><span style="color: rgb(0, 0, 0); font-weight: bold;">'</span><span style="color: rgb(0, 0, 0); font-weight: bold;">print&nbsp;$2&nbsp;&nbsp;if&nbsp;/(&lt;p&gt;)?("w*)(?(1)&lt;"/p&gt;|"d)/</span><span style="color: rgb(0, 0, 0); font-weight: bold;">'</span><span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 128, 0);">#</span><span style="color: rgb(0, 128, 0);">&nbsp;print&nbsp;xx<br />
<br />
</span><br />
<br />
<br />
<img src ="http://www.blogjava.net/Skynet/aggbug/292835.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/Skynet/" target="_blank">刘凯毅</a> 2009-08-27 16:04 <a href="http://www.blogjava.net/Skynet/archive/2009/08/27/292835.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>perl vs php (转)</title><link>http://www.blogjava.net/Skynet/archive/2009/05/15/270947.html</link><dc:creator>刘凯毅</dc:creator><author>刘凯毅</author><pubDate>Fri, 15 May 2009 15:09:00 GMT</pubDate><guid>http://www.blogjava.net/Skynet/archive/2009/05/15/270947.html</guid><wfw:comment>http://www.blogjava.net/Skynet/comments/270947.html</wfw:comment><comments>http://www.blogjava.net/Skynet/archive/2009/05/15/270947.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/Skynet/comments/commentRss/270947.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Skynet/services/trackbacks/270947.html</trackback:ping><description><![CDATA[<br />
<br />
<h3>Perl/Php Translation</h3>
<table width="100%">
    <tbody>
        <tr valign="top">
            <td>
            <div style="margin-left: 20px;">arrays
            <p>hashes</p>
            <p>data structures</p>
            <p>array split/join</p>
            <p>case conversion</p>
            <p>string comparisons</p>
            <p>functions</p>
            </div>
            </td>
            <td>
            <div style="margin-left: 20px;">string matching operations
            <p>basename/dirname</p>
            <p>environment variables</p>
            <p>POST/GET parameters</p>
            <p>HTML elements</p>
            <p>URL encode</p>
            <p>MySQL database access</p>
            </div>
            </td>
        </tr>
    </tbody>
</table>
<hr />
<table width="100%">
    <tbody>
        <tr>
            <th align="left" width="50%">— Perl <span style="color: blue;">arrays </span>—</th>
            <th align="left" width="50%">— Php <span style="color: blue;">arrays </span>—</th>
        </tr>
        <tr valign="top">
            <td>
            <pre>@a = ();<br />
            <br />
            @a = ( 'xx', 11, 33.5, );<br />
            <br />
            @a = 12..33;<br />
            <br />
            $a[2] = 'something';<br />
            <br />
            $len = scalar(@a);<br />
            # or<br />
            $len = @a;<br />
            <br />
            @a3 = ('xx', @a1, @a2);<br />
            <br />
            ($x, $y) = @a;<br />
            <br />
            $a[@a] = 'new'; # push<br />
            <br />
            push<br />
            pop<br />
            shift<br />
            unshift<br />
            splice<br />
            <br />
            foreach $i (@a) { .. }<br />
            </pre>
            </td>
            <td>
            <pre>$a = array();<br />
            <br />
            $a = array( 'xx', 11, 33.5, );<br />
            <br />
            $a = range(12,33);<br />
            <br />
            $a[2] = 'something';<br />
            <br />
            $len = count($a);<br />
            <br />
            <br />
            <br />
            $a3 = array_merge('xx', $a1, $a2);<br />
            <br />
            list($x, $y) = $a;<br />
            <br />
            $a[] = 'new'; # push<br />
            <br />
            array_push<br />
            array_pop<br />
            array_shift<br />
            array_unshift<br />
            array_splice<br />
            <br />
            foreach ($a as $i) { .. }<br />
            </pre>
            </td>
        </tr>
    </tbody>
</table>
<table width="100%">
    <tbody>
        <tr>
            <th align="left" width="50%">— Perl <span style="color: blue;">hashes </span>—</th>
            <th align="left" width="50%">— Php <span style="color: blue;">hashes </span>—</th>
        </tr>
        <tr valign="top">
            <td>
            <pre>%h = ();<br />
            <br />
            %h = ( 'x' => 'y',<br />
            'z' => 'w',<br />
            );<br />
            <br />
            $h{'x'} = 7;<br />
            <br />
            while (($key,$value) = each(%h))<br />
            { .. }<br />
            <br />
            $a = keys(%h);<br />
            $b = values(%h);<br />
            <br />
            delete $h{'x'};<br />
            </pre>
            </td>
            <td>
            <pre>$h = array();<br />
            <br />
            $h = array( 'x' => 'y',<br />
            'z' => 'w',<br />
            );<br />
            <br />
            $h['x'] = 7;<br />
            <br />
            foreach ($h as $key => $value)<br />
            { .. }<br />
            <br />
            $a = array_keys($h);<br />
            $b = array_values($h);<br />
            <br />
            unset( $h['x'] );<br />
            <br />
            </pre>
            </td>
        </tr>
    </tbody>
</table>
<table width="100%">
    <tbody>
        <tr>
            <th align="left" width="50%">— Perl <span style="color: blue;">data structures </span>—</th>
            <th align="left" width="50%">— Php <span style="color: blue;">data structures </span>—</th>
        </tr>
        <tr valign="top">
            <td>
            <pre>%h = ('a'=>13, 'b'=>25);<br />
            @x = ('hi', 'there', 'all',);<br />
            <br />
            @mix = ( %h, @x,<br />
            [33..39],<br />
            { x=>15, yy=>23, },<br />
            );<br />
            <br />
            $mix[0]->{'b'}  # == 25<br />
            $mix[0]{'b'}    # == 25<br />
            $mix[2]->[2]    # == 35<br />
            $mix[2][2]      # == 35<br />
            <br />
            </pre>
            </td>
            <td>
            <pre>$h = array('a'=>13, 'b'=>25);<br />
            $x = array('hi', 'there', 'all',);<br />
            <br />
            $mix = array($h, $x,<br />
            range(33,39),<br />
            array('x'=>15, 'yy'=>23),<br />
            );<br />
            <br />
            $mix[0]['b']  # == 25<br />
            <br />
            $mix[2][2]    # == 35<br />
            <br />
            </pre>
            </td>
        </tr>
    </tbody>
</table>
<table width="100%">
    <tbody>
        <tr>
            <th align="left" width="50%">— Perl <span style="color: blue;">array split/join </span>—</th>
            <th align="left" width="50%">— Php <span style="color: blue;">array split/join </span>—</th>
        </tr>
        <tr valign="top">
            <td>
            <pre>@a = split( '|', $s );<br />
            <br />
            @a = split( 's+', $s );<br />
            <br />
            <br />
            $s = join( '|', @a );<br />
            </pre>
            </td>
            <td>
            <pre>$a = preg_split( '/|/', $s,<br />
            -1, PREG_SPLIT_NO_EMPTY );<br />
            $a = preg_split( '/s+/', $s,<br />
            -1, PREG_SPLIT_NO_EMPTY );<br />
            <br />
            $s = join( '|', $a );<br />
            </pre>
            </td>
        </tr>
    </tbody>
</table>
<table width="100%">
    <tbody>
        <tr>
            <th align="left" width="50%">— Perl <span style="color: blue;">case conversion </span>—</th>
            <th align="left" width="50%">— Php <span style="color: blue;">case conversion </span>—</th>
        </tr>
        <tr valign="top">
            <td>
            <pre>$s = lc($s);<br />
            $s = uc($s);<br />
            <br />
            $s =~ tr/a-z/A-Z/;<br />
            </pre>
            </td>
            <td>
            <pre>$s = strtolower($s);<br />
            $s = strtoupper($s);<br />
            <br />
            <br />
            </pre>
            </td>
        </tr>
    </tbody>
</table>
<table width="100%">
    <tbody>
        <tr>
            <th align="left" width="50%">— Perl <span style="color: blue;">string comparisons </span>—</th>
            <th align="left" width="50%">— Php <span style="color: blue;">string comparisons </span>—</th>
        </tr>
        <tr valign="top">
            <td>
            <pre>$s1 eq $s2<br />
            <br />
            <br />
            <br />
            $s1 lt $s2<br />
            </pre>
            </td>
            <td>
            <pre>strcmp($s1,$s2) == 0<br />
            # or<br />
            $s1 === $s2<br />
            <br />
            strcmp($s1,$s2) &lt; 0<br />
            </pre>
            </td>
        </tr>
    </tbody>
</table>
<table width="100%">
    <tbody>
        <tr>
            <th align="left" width="50%">— Perl <span style="color: blue;">functions </span>—</th>
            <th align="left" width="50%">— Php <span style="color: blue;">functions </span>—</th>
        </tr>
        <tr valign="top">
            <td>
            <pre>sub foo {<br />
            my @args = @_;<br />
            }<br />
            <br />
            sub foo {<br />
            $x = 5;<br />
            }<br />
            <br />
            <br />
            <br />
            <br />
            <br />
            foo2( @a, %h );<br />
            </pre>
            </td>
            <td>
            <pre>function foo() {<br />
            $args = func_get_args();<br />
            }<br />
            <br />
            function foo() {<br />
            global $x;<br />
            $x = 5;<br />
            }<br />
            <br />
            function foo2($x, $y) {<br />
            }<br />
            <br />
            foo2( $a, $h );<br />
            </pre>
            </td>
        </tr>
    </tbody>
</table>
<table width="100%">
    <tbody>
        <tr>
            <th align="left" width="50%">— Perl <span style="color: blue;">string matching operations </span>—</th>
            <th align="left" width="50%">— Php <span style="color: blue;">string matching operations </span>—</th>
        </tr>
        <tr valign="top">
            <td>
            <pre>$s =~ m/(w+)/;<br />
            $substr = $1;<br />
            <br />
            @all = ($s =~ m/(w+)/g);<br />
            <br />
            <br />
            $s =~ s/s+/X/;<br />
            $s =~ s/s+/X/g;<br />
            <br />
            $s =~ s/^s+|s+$//g;<br />
            </pre>
            </td>
            <td>
            <pre>preg_match( "/(w+)/", $s, $match );<br />
            $substr = $match[1];<br />
            <br />
            preg_match_all( "/(w+)/", $s, $match );<br />
            $all = $match[0];<br />
            <br />
            $s = preg_replace( "/s+/", 'X', $s, 1 );<br />
            $s = preg_replace( "/s+/", 'X', $s );<br />
            <br />
            $s = trim($s);<br />
            </pre>
            </td>
        </tr>
    </tbody>
</table>
<table width="100%">
    <tbody>
        <tr>
            <th align="left" width="50%">— Perl <span style="color: blue;">basename/dirname </span>—</th>
            <th align="left" width="50%">— Php <span style="color: blue;">basename/dirname </span>—</th>
        </tr>
        <tr valign="top">
            <td>
            <pre>use File::Basename;<br />
            <br />
            $b = basename($path);<br />
            $d = dirname($path);<br />
            </pre>
            </td>
            <td>
            <pre> <br />
            <br />
            $b = basename($path);<br />
            $d = dirname($path);<br />
            </pre>
            </td>
        </tr>
    </tbody>
</table>
<table width="100%">
    <tbody>
        <tr>
            <th align="left" width="50%">— Perl <span style="color: blue;">environment variables </span>—</th>
            <th align="left" width="50%">— Php <span style="color: blue;">environment variables </span>—</th>
        </tr>
        <tr valign="top">
            <td>
            <pre>%ENV<br />
            <br />
            $ENV{REQUEST_METHOD}<br />
            <br />
            $ARGV[$i]<br />
            <br />
            $0<br />
            </pre>
            </td>
            <td>
            <pre>$_SERVER<br />
            <br />
            $_SERVER[REQUEST_METHOD]<br />
            <br />
            $argv[$i+1]<br />
            <br />
            $argv[0]  # Php/CGI only<br />
            </pre>
            </td>
        </tr>
    </tbody>
</table>
<table width="100%">
    <tbody>
        <tr>
            <th align="left" width="50%">— Perl <span style="color: blue;">POST/GET parameters </span>—</th>
            <th align="left" width="50%">— Php <span style="color: blue;">POST/GET parameters </span>—</th>
        </tr>
        <tr valign="top">
            <td>
            <pre>#form/hyperlink parameters:<br />
            # s : single-valued<br />
            # m : multi-valued<br />
            <br />
            use CGI (:standard);<br />
            <br />
            <br />
            <br />
            <br />
            $s = param('s');<br />
            @m = param('m');<br />
            <br />
            @param_names = param();<br />
            $num_params = param();<br />
            </pre>
            </td>
            <td>
            <pre>#form/hyperlink parameters:<br />
            # s   : single-valued<br />
            # m[] : multi-valued<br />
            #       (such as multi-selections<br />
            #        and checkbox groups)<br />
            <br />
            $PARAM<br />
            = array_merge($_GET, $_POST);<br />
            <br />
            $s = $PARAM['s'];  # a scalar<br />
            $m = $PARAM['m'];  # an array<br />
            <br />
            $param_names = array_keys($PARAM);<br />
            $num_params = count($PARAM);<br />
            </pre>
            </td>
        </tr>
    </tbody>
</table>
<table width="100%">
    <tbody>
        <tr>
            <th align="left" width="50%">— Perl <span style="color: blue;">HTML elements </span>—</th>
            <th align="left" width="50%">— Php <span style="color: blue;">HTML elements </span>—</th>
        </tr>
        <tr valign="top">
            <td>
            <pre>use CGI (:standard);<br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            $ref = "x.cgi";<br />
            a({href=>$ref}, "yy")<br />
            <br />
            textfield({name=>"yy", size=>5})<br />
            <br />
            password({name=>"yy", size=>5})<br />
            <br />
            textarea({name=>"yy",<br />
            cols=>5, rows=>2})<br />
            <br />
            submit({value=>"yy"})<br />
            <br />
            button( {name=>"xx",<br />
            value=>"yy",<br />
            onclick=>"submit()",<br />
            }<br />
            )<br />
            <br />
            %labels = (0=>'a',1=>'q',2=>'x');<br />
            popup_menu( { name=>"xx",<br />
            values=>[0..2],<br />
            labels=>%labels,<br />
            size=>4,<br />
            }<br />
            )<br />
            <br />
            <br />
            @a = ('xx','yy','zz');<br />
            radio_group( { name=>'nn',<br />
            values=> @a,<br />
            default=>'_',<br />
            linebreak=>1,<br />
            }<br />
            )<br />
            <br />
            %labels = ('xx'=>'L1','yy'=>'L2');<br />
            @a = keys( %labels );<br />
            checkbox_group( { name=>'nn',<br />
            values=> @a,<br />
            labels=> %labels,<br />
            }<br />
            )<br />
            <br />
            table(<br />
            Tr(<br />
            [<br />
            td(['a','b']),<br />
            td(['x','y']),<br />
            ]<br />
            )<br />
            )<br />
            <br />
            </pre>
            </td>
            <td>
            <pre># The Perl/CGI functions have the<br />
            # additional property of "stability"<br />
            # when used in reentrant forms.<br />
            # The values of the HTML elements are<br />
            # set according to the incoming<br />
            # parameter values for those elements.<br />
            # The versions below are not stable.<br />
            <br />
            $ref = "x.php";<br />
            &lt;a href="&lt;?php echo $ref?>">yy&lt;/a><br />
            <br />
            &lt;input type=text name=yy size=5><br />
            <br />
            &lt;input type=password name=yy size=5><br />
            <br />
            &lt;textarea name=yy cols=5 rows=2><br />
            <br />
            &lt;/textarea><br />
            <br />
            &lt;input type="submit" value=yy><br />
            <br />
            &lt;input type="button"<br />
            name="xx" value="yy"<br />
            onclick="submit()"><br />
            <br />
            <br />
            <br />
            &lt;select name="xx" size="4"><br />
            &lt;?php<br />
            $labels = array(0=>'a',1=>'q',2=>'x');<br />
            foreach (range(0,2) as $_)<br />
            echo "&lt;option value='$_'>",<br />
            $labels[$_];<br />
            ?><br />
            <br />
            &lt;/select><br />
            <br />
            $a = array('xx','yy','zz');<br />
            foreach ($a as $_)<br />
            echo "&lt;input type=radio<br />
            name=nn value='$_'>$_&lt;br>";<br />
            <br />
            <br />
            <br />
            <br />
            $labels = array('xx'=>'L1','yy'=>'L2');<br />
            foreach (array_keys($labels) as $_)<br />
            echo "&lt;input type=checkbox<br />
            name=nn value='$_'>",<br />
            $labels[$_];<br />
            <br />
            <br />
            <br />
            &lt;table><br />
            &lt;tr><br />
            &lt;td>a&lt;/td>&lt;td>b&lt;/td><br />
            <br />
            &lt;/tr><br />
            &lt;tr><br />
            &lt;td>x&lt;/td>&lt;td>y&lt;/td><br />
            &lt;/tr><br />
            &lt;/table><br />
            </pre>
            </td>
        </tr>
    </tbody>
</table>
<table width="100%">
    <tbody>
        <tr>
            <th align="left" width="50%">— Perl <span style="color: blue;">URL encode </span>—</th>
            <th align="left" width="50%">— Php <span style="color: blue;">URL encode </span>—</th>
        </tr>
        <tr valign="top">
            <td>
            <pre>use URI::Escape;<br />
            <br />
            uri_escape($val)<br />
            uri_unescape($val)<br />
            </pre>
            </td>
            <td>
            <pre> <br />
            <br />
            <br />
            urlencode($val)<br />
            urldecode($val)<br />
            </pre>
            </td>
        </tr>
    </tbody>
</table>
<table width="100%">
    <tbody>
        <tr>
            <th align="left" width="50%">— Perl <span style="color: blue;">MySQL database access </span>—</th>
            <th align="left" width="50%">— Php <span style="color: blue;">MySQL database access </span>—</th>
        </tr>
        <tr valign="top">
            <td>
            <pre>use DBI;<br />
            $dbh = DBI->connect(<br />
            'DBI:mysql:test:localhost',<br />
            $usr,$pwd<br />
            );<br />
            <br />
            $dbh->do( $sql_op )<br />
            <br />
            $query = $dbh->prepare( $sql_op );<br />
            $query->execute();<br />
            <br />
            while(<br />
            @record = $query->fetchrow() )<br />
            { .. }<br />
            <br />
            <br />
            $dbh->quote($val)<br />
            <br />
            <br />
            <br />
            </pre>
            </td>
            <td>
            <pre> <br />
            $dbh = mysql_connect(<br />
            'localhost', $usr, $pwd<br />
            );<br />
            mysql_query('USE test')<br />
            <br />
            mysql_query( $sql_op );<br />
            <br />
            $results = mysql_query( $sql_op );<br />
            <br />
            <br />
            while($record =<br />
            mysql_fetch_row($results))<br />
            { .. }<br />
            <br />
            <br />
            "'" . addslashes($val) . "'"<br />
            </pre>
            </td>
        </tr>
    </tbody>
</table>
<br />
<img src ="http://www.blogjava.net/Skynet/aggbug/270947.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/Skynet/" target="_blank">刘凯毅</a> 2009-05-15 23:09 <a href="http://www.blogjava.net/Skynet/archive/2009/05/15/270947.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>perl 使用</title><link>http://www.blogjava.net/Skynet/archive/2009/04/01/263353.html</link><dc:creator>刘凯毅</dc:creator><author>刘凯毅</author><pubDate>Wed, 01 Apr 2009 06:12:00 GMT</pubDate><guid>http://www.blogjava.net/Skynet/archive/2009/04/01/263353.html</guid><wfw:comment>http://www.blogjava.net/Skynet/comments/263353.html</wfw:comment><comments>http://www.blogjava.net/Skynet/archive/2009/04/01/263353.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.blogjava.net/Skynet/comments/commentRss/263353.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Skynet/services/trackbacks/263353.html</trackback:ping><description><![CDATA[<br />
<br />
对应脚本运用：<br />
&nbsp; 1.&nbsp; shell&nbsp; 统筹管理 脚本的运行。合理结合 crontab ,&nbsp; ps -ef ,kill 等命令。<br />
&nbsp;&nbsp; 2.&nbsp; perl&nbsp; 处理短小快 。<br />
&nbsp;&nbsp; 3.&nbsp; python 有比较复杂结构和逻辑的。<br />
&nbsp;<br />
本文主要介绍 perl 的行级命令使用 ，力求 短 小 快 <img alt="" src="/CuteSoft_Client/CuteEditor/images/emsmile.gif" align="absmiddle" border="0" />：<br />
<div style="padding: 4px 5px 4px 4px; font-size: 13px; border-left-color: #cccccc; width: 98%; background-color: #eeeeee;"><img alt="" src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /><span style="color: #008000;">#</span><span style="color: #008000;">最简单的</span><span style="color: #008000;"><br />
<img alt="" src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /></span><span style="color: #000000;">$&nbsp;perl&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">e&nbsp;</span><span style="font-weight: bold; color: #000000;">'</span><span style="font-weight: bold; color: #000000;">print&nbsp;"Hello&nbsp;World\n"</span><span style="font-weight: bold; color: #000000;">'</span></div>
<br />
<div style="padding: 4px 5px 4px 4px; font-size: 13px; border-left-color: #cccccc; width: 98%; background-color: #eeeeee;"><img alt="" src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /><span style="color: #008000;">#</span><span style="color: #008000;">处理文件&nbsp;行</span><span style="color: #008000;"><br />
<img alt="" src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /></span><span style="color: #000000;">$&nbsp;perl&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">n&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">e&nbsp;</span><span style="font-weight: bold; color: #000000;">'</span><span style="font-weight: bold; color: #000000;">print&nbsp;$_</span><span style="font-weight: bold; color: #000000;">'</span><span style="color: #000000;">&nbsp;file1</span></div>
<br />
<div style="padding: 4px 5px 4px 4px; font-size: 13px; border-left-color: #cccccc; width: 98%; background-color: #eeeeee;"><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" alt="" align="top" /><span style="color: #000000;"><br />
<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" alt="" align="top" /></span><span style="color: #008000;">#</span><span style="color: #008000;">编码转换<br />
<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" alt="" align="top" />#如果&nbsp;有需要&nbsp;在使用下&nbsp;&nbsp;encode("UTF-8",&nbsp;<span style="color: #000000; font-weight: bold;">decode("GBK",$_)</span>);在&nbsp;linux&nbsp;下默认&nbsp;utf-8</span><span style="color: #008000;"><br />
<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" alt="" align="top" /></span><span style="color: #000000;">perl&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">MEncode&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">ne&nbsp;</span><span style="font-weight: bold; color: #000000;">'</span><span style="font-weight: bold; color: #000000;">print&nbsp;decode("GBK",$_);</span><span style="font-weight: bold; color: #000000;">'</span><span style="color: #000000;">&nbsp;&nbsp;file</span><span style="color: #000000;">.</span><span style="color: #000000;">txt<br />
<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" alt="" align="top" /><br />
<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" alt="" align="top" /></span></div>
<br />
<br />
<br />
<div style="padding: 4px 5px 4px 4px; font-size: 13px; border-left-color: #cccccc; width: 98%; background-color: #eeeeee;"><img alt="" src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /><span style="color: #008000;">#</span><span style="color: #008000;">正则使用 <br />
&nbsp;&nbsp; #&nbsp; if($_=~/.*\/(.*)$/){&nbsp; print $1 ;}&nbsp; 这是perl 巨方便的地方 $1 xx &nbsp;<br />
<img alt="" src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />#&nbsp;next&nbsp;LINE&nbsp;跳到下一个循环</span><span style="color: #008000;"><br />
<img alt="" src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /></span><span style="color: #000000;">$&nbsp;perl&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">n&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">e&nbsp;</span><span style="font-weight: bold; color: #000000;">'</span><span style="font-weight: bold; color: #000000;">next&nbsp;LINE&nbsp;unless&nbsp;/pattern/;&nbsp;print&nbsp;$_</span><span style="font-weight: bold; color: #000000;">'</span></div>
<br />
<br />
<div style="padding: 4px 5px 4px 4px; font-size: 13px; border-left-color: #cccccc; width: 98%; background-color: #eeeeee;"><img alt="" src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /><span style="color: #008000;">#</span><span style="color: #008000;">去除换行&nbsp;</span><span style="color: #008000;"><span style="border-collapse: collapse; color: #000000; font-family: Arial; white-space: pre;">chomp</span><br />
<img alt="" src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /></span><span style="color: #000000;">perl&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">e&nbsp;</span><span style="font-weight: bold; color: #000000;">'</span><span style="font-weight: bold; color: #000000;">print&nbsp;split(/\n/,"asg\n");</span><span style="font-weight: bold; color: #000000;">'</span></div>
<br />
<br />
<div style="padding: 4px 5px 4px 4px; font-size: 13px; border-left-color: #cccccc; width: 98%; background-color: #eeeeee;"><img alt="" src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /><span style="color: #008000;">#</span><span style="color: #008000;">像&nbsp;awk&nbsp;一样&nbsp;Begin&nbsp;End</span><span style="color: #008000;"><br />
<img alt="" src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /></span><span style="color: #000000;">$&nbsp;perl&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">ne&nbsp;</span><span style="font-weight: bold; color: #000000;">'</span><span style="font-weight: bold; color: #000000;">END&nbsp;{&nbsp;print&nbsp;$t&nbsp;}&nbsp;@w&nbsp;=&nbsp;/(\w+)/g;&nbsp;$t&nbsp;+=&nbsp;@w</span><span style="font-weight: bold; color: #000000;">'</span><span style="color: #000000;">&nbsp;file</span><span style="color: #000000;">.</span><span style="color: #000000;">txt&nbsp;</span></div>
<br />
<div style="padding: 4px 5px 4px 4px; font-size: 13px; border-left-color: #cccccc; width: 98%; background-color: #eeeeee;"><img alt="" src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /><span style="color: #008000;">#</span><span style="color: #008000;">像&nbsp;awk&nbsp;-F"x"&nbsp;一样&nbsp;切割行<br />
<img alt="" src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />#-a&nbsp;打开自动分离&nbsp;(split)&nbsp;&nbsp;模式<br />
<img alt="" src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />#@F&nbsp;为&nbsp;切割后的&nbsp;数组</span><span style="color: #008000;"><br />
<img alt="" src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /></span><span style="color: #000000;">perl&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">F</span><span style="font-weight: bold; color: #000000;">'</span><span style="font-weight: bold; color: #000000;">\t</span><span style="font-weight: bold; color: #000000;">'</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">ane&nbsp;</span><span style="font-weight: bold; color: #000000;">'</span><span style="font-weight: bold; color: #000000;"><br />
<img alt="" src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />&nbsp;if($F[1]=~/侃侃/&nbsp;and&nbsp;$F[2]=~/爱情啊/){<br />
<img alt="" src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print&nbsp;"$F[3]\t$F[4]\t$F[5]\n"<br />
<img alt="" src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />&nbsp;&nbsp;}<br />
<img alt="" src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /></span><span style="font-weight: bold; color: #000000;">'</span><span style="color: #000000;">&nbsp;all2_data</span><span style="color: #000000;">.</span><span style="color: #0000ff;">sort</span><span style="color: #000000;">.</span><span style="color: #000000;">st<br />
<img alt="" src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /></span></div>
<br />
实际处理：<br />
&nbsp; <br />
<div style="border: 1px solid #cccccc; padding: 4px 5px 4px 4px; background-color: #eeeeee; font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: #000000;">perl&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">F</span><span style="color: #000000; font-weight: bold;">'</span><span style="color: #000000; font-weight: bold;">\|\|</span><span style="color: #000000; font-weight: bold;">'</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">ane&nbsp;</span><span style="color: #000000; font-weight: bold;">'</span><span style="color: #000000; font-weight: bold;"><br />
&nbsp;my&nbsp;$actor,$music&nbsp;;<br />
&nbsp;if&nbsp;&nbsp;(&nbsp;$F[3]&nbsp;){<br />
&nbsp;&nbsp;$music=$F[2];<br />
&nbsp;&nbsp;$actor=$F[3];<br />
&nbsp;}else{<br />
&nbsp;&nbsp;$music=$F[0];<br />
&nbsp;&nbsp;$actor=$F[1];&nbsp;<br />
&nbsp;}<br />
&nbsp;&nbsp;$music&nbsp;=~&nbsp;tr/[A-Z]/[a-z]/;<br />
&nbsp;&nbsp;$music&nbsp;=~&nbsp;s/\s*(.*)\s*\(.*\)/\1/g;<br />
&nbsp;&nbsp;$actor&nbsp;=~&nbsp;tr/[A-Z]/[a-z]/;<br />
&nbsp;&nbsp;$actor&nbsp;=~&nbsp;s/\s*(.*)\s*\(.*\)/\1/g;<br />
print&nbsp;"$actor-$music\n";<br />
</span><span style="color: #000000; font-weight: bold;">'</span><span style="color: #000000;">&nbsp;ring</span><span style="color: #000000;">.</span><span style="color: #000000;">utf8</span><span style="color: #000000;">.</span><span style="color: #000000;">txt&nbsp;&nbsp;</span><span style="color: #000000;">|</span><span style="color: #0000ff;">sort</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">u&nbsp;&nbsp;</span><span style="color: #000000;">&gt;</span><span style="color: #000000;">&nbsp;ring</span><span style="color: #000000;">.</span><span style="color: #000000;">actor_music</span><span style="color: #000000;">.</span><span style="color: #0000ff;">sort</span><span style="color: #000000;">.</span><span style="color: #000000;">utf8</span><span style="color: #000000;">.</span><span style="color: #000000;">txt&nbsp;</span><span style="color: #000000;">&amp;</span><span style="color: #000000;"><br />
wc&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">l&nbsp;ring</span><span style="color: #000000;">.</span><span style="color: #000000;">actor_music</span><span style="color: #000000;">.</span><span style="color: #0000ff;">sort</span><span style="color: #000000;">.</span><span style="color: #000000;">utf8</span><span style="color: #000000;">.</span><span style="color: #000000;">txt<br />
</span></div>
<br />
<br />
<div style="padding: 4px 5px 4px 4px; font-size: 13px; border-left-color: #cccccc; width: 98%; background-color: #eeeeee;"><img alt="" src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /><span style="color: #008000;">#</span><span style="color: #008000;">像&nbsp;sed&nbsp;一样替换<br />
</span><span style="color: #008000;">&nbsp;&nbsp;&nbsp; # -i 和 sed 一样 perl 输出会替换调 源 file.txt<br />
<img alt="" src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /></span><span style="color: #000000;">$&nbsp;perl&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">i&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">pe&nbsp;</span><span style="font-weight: bold; color: #000000;">'</span><span style="font-weight: bold; color: #000000;">s/\bPHP\b/Perl/g</span><span style="font-weight: bold; color: #000000;">'</span><span style="color: #000000;">&nbsp;file</span><span style="color: #000000;">.</span><span style="color: #000000;">txt</span></div>
<br />
<br />
<div style="padding: 4px 5px 4px 4px; font-size: 13px; border-left-color: #cccccc; width: 98%; background-color: #eeeeee;"><img alt="" src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /><span style="color: #008000;">#</span><span style="color: #008000;">外部&nbsp;传参</span><span style="color: #008000;"><br />
<img alt="" src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /></span><span style="color: #000000;">perl&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">ne</span><span style="font-weight: bold; color: #000000;">'</span><span style="font-weight: bold; color: #000000;">print&nbsp;"$ARGV[0]\t$ARGV[1]\n"&nbsp;</span><span style="font-weight: bold; color: #000000;">'</span><span style="color: #000000;">&nbsp;file</span><span style="color: #000000;">.</span><span style="color: #000000;">txt&nbsp;</span><span style="font-weight: bold; color: #000000;">'</span><span style="font-weight: bold; color: #000000;">par1</span><span style="font-weight: bold; color: #000000;">'</span><span style="color: #000000;">&nbsp;</span><span style="font-weight: bold; color: #000000;">'</span><span style="font-weight: bold; color: #000000;">par2</span><span style="font-weight: bold; color: #000000;">'<br />
&nbsp;&nbsp;&nbsp; #结果 .. &nbsp;par1&nbsp;&nbsp;&nbsp;&nbsp; par2 ..</span></div>
<br />
<br />
<br />
<div style="border: 1px solid #cccccc; padding: 4px 5px 4px 4px; background-color: #eeeeee; font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: #008000;">#</span><span style="color: #008000;">&nbsp;查询出&nbsp;重复列&nbsp;次数，并&nbsp;列举出来</span><span style="color: #008000;"><br />
</span><span style="color: #000000;">cut&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">d</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000; font-weight: bold;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000;">&nbsp;&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">f&nbsp;</span><span style="color: #800000;">2</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">.</span><span style="color: #000000;">collection_mobile</span><span style="color: #000000;">.</span><span style="color: #000000;">data&nbsp;</span><span style="color: #000000;">|</span><span style="color: #000000;">perl&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">ne&nbsp;</span><span style="color: #000000; font-weight: bold;">'</span><span style="color: #000000; font-weight: bold;"><br />
&nbsp;&nbsp;&nbsp;END{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;while&nbsp;(($key,$value)=each(%a)){print&nbsp;$key,"=",$value,"\n";};<br />
&nbsp;&nbsp;&nbsp;}BEGIN{&nbsp;%a&nbsp;=();&nbsp;}&nbsp;<br />
&nbsp;&nbsp;&nbsp;chomp;<br />
&nbsp;&nbsp;&nbsp;$a{$_}+=1;&nbsp;<br />
&nbsp;</span><span style="color: #000000; font-weight: bold;">'</span></div>
结果<br />
Ring=532895<br />
CRBT=68500<br />
RingBoxes=880<br />
Song=96765<br />
<br />
&nbsp;
<div style="padding: 4px 5px 4px 4px; font-size: 13px; border-left-color: #cccccc; width: 98%; background-color: #eeeeee;"><img alt="" src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /><span style="color: #008000;">#一些实际</span><span style="color: #008000;">使用&nbsp;:)</span><span style="color: #008000;"><br />
<img alt="" src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /></span><span style="color: #000000;">find&nbsp;</span><span style="color: #000000;">.</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">name&nbsp;</span><span style="font-weight: bold; color: #000000;">"</span><span style="font-weight: bold; color: #000000;">*.mp3</span><span style="font-weight: bold; color: #000000;">"</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">|</span><span style="color: #000000;">&nbsp;perl&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">pe&nbsp;</span><span style="font-weight: bold; color: #000000;">'</span><span style="font-weight: bold; color: #000000;">s/.\/\w+-(\w+)-.*/$1/</span><span style="font-weight: bold; color: #000000;">'</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">|</span><span style="color: #000000;">&nbsp;</span><span style="color: #0000ff;">sort</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">|</span><span style="color: #000000;">&nbsp;uniq<br />
&nbsp;&nbsp; perl -F'\t' -ane 'if($F[1]=~/$ARGV[0]/ and $F[2]=~/$ARGV[1]/){print "$F[3]\t$F[4]\t$F[5]\n"}' all2_data.sort.st '侃侃' '爱情啊'<br />
</span></div>
<br />
<div style="border: 1px solid #cccccc; padding: 4px 5px 4px 4px; background-color: #eeeeee; font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: #008000;">#</span><span style="color: #008000;">与&nbsp;find&nbsp;合用&nbsp;-e&nbsp;$ARGV[0]</span><span style="color: #008000;"> 批量 把 excel 倒成 文本 格式<br />
</span><span style="color: #000000;">find&nbsp;</span><span style="color: #000000;">.</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">maxdepth&nbsp;</span><span style="color: #800000;">1</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">name&nbsp;</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000; font-weight: bold;">*xls</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">-</span><span style="color: #0000ff;">exec</span><span style="color: #000000;">&nbsp;perl&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">e&nbsp;</span><span style="color: #000000; font-weight: bold;">'</span><span style="color: #000000; font-weight: bold;"><br />
</span>
<div style="border: 1px solid #cccccc; padding: 4px 5px 4px 4px; background-color: #eeeeee; font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: #0000ff;">require</span><span style="color: #000000;">(</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000; font-weight: bold;">/home/xj_liukaiyi/src/perl/excel/excelUtil.pl</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000;">);<br />
</span><span style="color: #0000ff;">my</span><span style="color: #000000;">&nbsp;</span><span style="color: #800080;">$file</span><span style="color: #000000;">=</span><span style="color: #800080;">$ARGV</span><span style="color: #000000;">[</span><span style="color: #800000;">0</span><span style="color: #000000;">];<br />
</span><span style="color: #0000ff;">sub</span><span style="color: #000000;">&nbsp;myRead{<br />
&nbsp;&nbsp;</span><span style="color: #0000ff;">my</span><span style="color: #000000;">&nbsp;</span><span style="color: #800080;">$str</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000; font-weight: bold;">""</span><span style="color: #000000;">;<br />
&nbsp;&nbsp;</span><span style="color: #0000ff;">for</span><span style="color: #000000;">&nbsp;</span><span style="color: #800080;">$tmp</span><span style="color: #000000;">(</span><span style="color: #800080;">@_</span><span style="color: #000000;">){<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #800080;">$str</span><span style="color: #000000;">=</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000; font-weight: bold;">$str$tmp\t</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000;">;<br />
&nbsp;&nbsp;}<br />
&nbsp;&nbsp;</span><span style="color: #800080;">$str</span><span style="color: #000000;">=</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000; font-weight: bold;">$str\n</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000;">;<br />
&nbsp;&nbsp;</span><span style="color: #0000ff;">system</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000; font-weight: bold;">echo&nbsp;\</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #800080;">$str</span><span style="color: #000000;">\</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000; font-weight: bold;">&nbsp;&gt;&gt;&nbsp;$file.data&nbsp;</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000;">;<br />
}<br />
</span><span style="color: #000000;">&amp;</span><span style="color: #000000;">parse_excel(</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000; font-weight: bold;">$file</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000;">,</span><span style="color: #800000;">0</span><span style="color: #000000;">,\&amp;</span><span style="color: #000000;">myRead);<br />
</span><span style="color: #0000ff;">print</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000; font-weight: bold;">$file\n</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000;">;</span></div>
<span style="color: #000000; font-weight: bold;">'</span><span style="color: #000000;">&nbsp;{}&nbsp;</span><span style="color: #000000;">\</span><span style="color: #000000;">;<br />
</span></div>
<br />
<br />
<br />
<br />
参考：<br />
<a href="http://www.ibm.com/developerworks/cn/linux/sdk/perl/l-p101/index.html">http://www.ibm.com/developerworks/cn/linux/sdk/perl/l-p101/index.html<br />
</a><a href="http://bbs.chinaunix.net/viewthread.php?tid=499434">http://bbs.chinaunix.net/viewthread.php?tid=499434</a><br />
<br />
<br />
<br />
<img src ="http://www.blogjava.net/Skynet/aggbug/263353.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/Skynet/" target="_blank">刘凯毅</a> 2009-04-01 14:12 <a href="http://www.blogjava.net/Skynet/archive/2009/04/01/263353.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>perl 一些有用的 util </title><link>http://www.blogjava.net/Skynet/archive/2009/03/17/260234.html</link><dc:creator>刘凯毅</dc:creator><author>刘凯毅</author><pubDate>Tue, 17 Mar 2009 05:49:00 GMT</pubDate><guid>http://www.blogjava.net/Skynet/archive/2009/03/17/260234.html</guid><wfw:comment>http://www.blogjava.net/Skynet/comments/260234.html</wfw:comment><comments>http://www.blogjava.net/Skynet/archive/2009/03/17/260234.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/Skynet/comments/commentRss/260234.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Skynet/services/trackbacks/260234.html</trackback:ping><description><![CDATA[比如 日志，和shell运行<br />
<div style="padding: 4px 5px 4px 4px; border-left-color: #cccccc; background-color: #eeeeee; font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: #008000;">#</span><span style="color: #008000;">!/bin/perl&nbsp;-w</span><span style="color: #008000;"><br />
</span><span style="color: #0000ff;">use</span><span style="color: #000000;">&nbsp;</span><span style="color: #0000ff;">Time</span><span style="color: #000000;">::</span><span style="color: #0000ff;">Local</span><span style="color: #000000;">;<br />
<br />
</span><span style="color: #0000ff;">my</span><span style="color: #000000;">&nbsp;</span><span style="color: #800080;">$log_input_file</span><span style="color: #000000;">=</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000; font-weight: bold;">~/log</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000;">;<br />
</span><span style="color: #0000ff;">sub</span><span style="color: #000000;">&nbsp;set_log_input_file{<br />
&nbsp;&nbsp;</span><span style="color: #800080;">$log_input_file</span><span style="color: #000000;">=</span><span style="color: #800080;">$_</span><span style="color: #000000;">[</span><span style="color: #800000;">0</span><span style="color: #000000;">];<br />
}<br />
<br />
<br />
</span><span style="color: #008000;">#</span><span style="color: #008000;">&amp;perl_log("tt","/home/xj_liukaiyi/log");</span><span style="color: #008000;"><br />
</span><span style="color: #0000ff;">sub</span><span style="color: #000000;">&nbsp;perl_log{<br />
&nbsp;&nbsp;</span><span style="color: #0000ff;">my</span><span style="color: #000000;">&nbsp;</span><span style="color: #800080;">$log_msg</span><span style="color: #000000;">=</span><span style="color: #0000ff;">shift</span><span style="color: #000000;">&nbsp;</span><span style="color: #800080;">@_</span><span style="color: #000000;">;<br />
&nbsp;&nbsp;</span><span style="color: #0000ff;">print</span><span style="color: #000000;">&nbsp;</span><span style="color: #800080;">$log_msg</span><span style="color: #000000;">,</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000; font-weight: bold;">\n</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000;">;<br />
&nbsp;&nbsp;</span><span style="color: #0000ff;">system</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000; font-weight: bold;">'</span><span style="color: #000000; font-weight: bold;">ttmp1=$(date&nbsp;+%Y-%k-%d);ttmp2=$(date&nbsp;+%M:%S);echo&nbsp;"$ttmp1&nbsp;$ttmp2:</span><span style="color: #000000; font-weight: bold;">'</span><span style="color: #000000;">.</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000; font-weight: bold;">$log_msg</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000;">.</span><span style="color: #000000; font-weight: bold;">'</span><span style="color: #000000; font-weight: bold;">"&nbsp;&gt;&gt;</span><span style="color: #000000; font-weight: bold;">'</span><span style="color: #000000;">.</span><span style="color: #800080;">$log_input_file</span><span style="color: #000000;">;<br />
}<br />
<br />
</span><span style="color: #008000;">#</span><span style="color: #008000;">&amp;system_util("xls&nbsp;-l","~/log");</span><span style="color: #008000;"><br />
</span><span style="color: #0000ff;">sub</span><span style="color: #000000;">&nbsp;system_util{<br />
&nbsp;&nbsp;</span><span style="color: #0000ff;">my</span><span style="color: #000000;">&nbsp;</span><span style="color: #800080;">$comm</span><span style="color: #000000;">=</span><span style="color: #0000ff;">shift</span><span style="color: #000000;">&nbsp;</span><span style="color: #800080;">@_</span><span style="color: #000000;">;<br />
&nbsp;&nbsp;</span><span style="color: #0000ff;">my</span><span style="color: #000000;">&nbsp;</span><span style="color: #800080;">@return</span><span style="color: #000000;">=</span><span style="color: #0000ff;">system</span><span style="color: #000000;">&nbsp;</span><span style="color: #800080;">$comm</span><span style="color: #000000;">;<br />
&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">&nbsp;(&nbsp;</span><span style="color: #800080;">$return</span><span style="color: #000000;">[(</span><span style="color: #800080;">@return</span><span style="color: #000000;">-</span><span style="color: #800000;">1</span><span style="color: #000000;">)]&nbsp;</span><span style="color: #000000;">==</span><span style="color: #000000;">&nbsp;</span><span style="color: #800000;">0</span><span style="color: #000000;">&nbsp;)&nbsp;{&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000;">&amp;</span><span style="color: #000000;">perl_log(</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000; font-weight: bold;">[success]</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000;">.</span><span style="color: #800080;">$comm</span><span style="color: #000000;">,</span><span style="color: #800080;">$log_input_file</span><span style="color: #000000;">);<br />
&nbsp;&nbsp;}</span><span style="color: #0000ff;">else</span><span style="color: #000000;">{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000;">&amp;</span><span style="color: #000000;">perl_log(</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000; font-weight: bold;">[error]</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000;">.</span><span style="color: #800080;">$comm</span><span style="color: #000000;">,</span><span style="color: #800080;">$log_input_file</span><span style="color: #000000;">);<br />
&nbsp;&nbsp;}<br />
&nbsp;&nbsp;</span><span style="color: #0000ff;">return</span><span style="color: #000000;">&nbsp;</span><span style="color: #800080;">$return</span><span style="color: #000000;">[(</span><span style="color: #800080;">@return</span><span style="color: #000000;">-</span><span style="color: #800000;">1</span><span style="color: #000000;">)];<br />
}<br />
<br />
</span><span style="color: #800000;">1</span><span style="color: #000000;">;<br />
</span></div>
<br />
excel 读取util&nbsp;<br />
<span style="font-size: 23px;">require("/home/xj_liukaiyi/src/perl/excel/excelUtil.pl");</span>&amp;parse_excel("2w.xls","歌曲列表","&amp;read_wlh);<br />
<div style="padding: 4px 5px 4px 4px; border-left-color: #cccccc; background-color: #eeeeee; font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: #008000;">#</span><span style="color: #008000;">!/bin/perl&nbsp;-w</span><span style="color: #008000;"><br />
</span><span style="color: #0000ff;">use</span><span style="color: #000000;">&nbsp;Spreadsheet</span><span style="color: #000000;">::</span><span style="color: #000000;">ParseExcel;<br />
</span><span style="color: #0000ff;">use</span><span style="color: #000000;">&nbsp;Spreadsheet</span><span style="color: #000000;">::</span><span style="color: #000000;">ParseExcel</span><span style="color: #000000;">::</span><span style="color: #000000;">FmtUnicode;&nbsp;<br />
</span><span style="color: #0000ff;">use</span><span style="color: #000000;">&nbsp;Encode;<br />
</span><span style="color: #0000ff;">use</span><span style="color: #000000;">&nbsp;Unicode</span><span style="color: #000000;">::</span><span style="color: #0000ff;">Map</span><span style="color: #000000;">();<br />
</span><span style="color: #0000ff;">my</span><span style="color: #000000;">&nbsp;</span><span style="color: #800080;">$Map</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;new&nbsp;Unicode</span><span style="color: #000000;">::</span><span style="color: #0000ff;">Map</span><span style="color: #000000;">(</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000; font-weight: bold;">GB2312</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000;">);<br />
<br />
<br />
</span><span style="color: #0000ff;">my</span><span style="color: #000000;">&nbsp;</span><span style="color: #800080;">$excelCODE</span><span style="color: #000000;">=</span><span style="color: #000000; font-weight: bold;">'</span><span style="color: #000000; font-weight: bold;">gb2312</span><span style="color: #000000; font-weight: bold;">'</span><span style="color: #000000;">;<br />
</span><span style="color: #0000ff;">my</span><span style="color: #000000;">&nbsp;</span><span style="color: #800080;">$coslCODE</span><span style="color: #000000;">=</span><span style="color: #000000; font-weight: bold;">'</span><span style="color: #000000; font-weight: bold;">utf8</span><span style="color: #000000; font-weight: bold;">'</span><span style="color: #000000;">;<br />
<br />
</span><span style="color: #0000ff;">my</span><span style="color: #000000;">&nbsp;</span><span style="color: #800080;">%parseCache</span><span style="color: #000000;">&nbsp;;<br />
</span><span style="color: #0000ff;">my</span><span style="color: #000000;">&nbsp;</span><span style="color: #800080;">%writeCache</span><span style="color: #000000;">&nbsp;;<br />
<br />
</span><span style="color: #0000ff;">my</span><span style="color: #000000;">&nbsp;</span><span style="color: #800080;">$oFmtJ</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;Spreadsheet</span><span style="color: #000000;">::</span><span style="color: #000000;">ParseExcel</span><span style="color: #000000;">::</span><span style="color: #000000;">FmtUnicode</span><span style="color: #000000;">-&gt;</span><span style="color: #000000;">new(Unicode_Map&nbsp;</span><span style="color: #000000;">=&gt;</span><span style="color: #800080;">$excelCODE</span><span style="color: #000000;">);&nbsp;<br />
</span><span style="color: #0000ff;">my</span><span style="color: #000000;">&nbsp;</span><span style="color: #800080;">$oExcel</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;new&nbsp;Spreadsheet</span><span style="color: #000000;">::</span><span style="color: #000000;">ParseExcel;<br />
<br />
<br />
<br />
</span><span style="color: #008000;">#</span><span style="color: #008000;"><br />
</span><span style="color: #008000;">#</span>&amp;parse_excel("all4.xls","乐扑","&amp;read_lp);&nbsp; <br />
<span style="color: #008000;"># sub read_lp{&nbsp; $_[1 .. 2.3&nbsp; ] } </span><br />
<span style="color: #0000ff;">sub</span><span style="color: #000000;">&nbsp;parse_excel{<br />
&nbsp;</span><span style="color: #0000ff;">my</span><span style="color: #000000;">&nbsp;</span><span style="color: #800080;">$sExcelName</span><span style="color: #000000;">=</span><span style="color: #0000ff;">shift</span><span style="color: #000000;">;<br />
&nbsp;</span><span style="color: #0000ff;">my</span><span style="color: #000000;">&nbsp;</span><span style="color: #800080;">$sSheetName</span><span style="color: #000000;">=</span><span style="color: #0000ff;">shift</span><span style="color: #000000;">;<br />
&nbsp;</span><span style="color: #0000ff;">my</span><span style="color: #000000;">&nbsp;</span><span style="color: #800080;">$action_fun</span><span style="color: #000000;">=</span><span style="color: #0000ff;">shift</span><span style="color: #000000;">;<br />
&nbsp;<br />
&nbsp;</span><span style="color: #0000ff;">my</span><span style="color: #000000;">(</span><span style="color: #800080;">$iR</span><span style="color: #000000;">,</span><span style="color: #000000;">&nbsp;</span><span style="color: #800080;">$iC</span><span style="color: #000000;">,</span><span style="color: #000000;">&nbsp;</span><span style="color: #800080;">$oWkS</span><span style="color: #000000;">,</span><span style="color: #800080;">$oWkC</span><span style="color: #000000;">);<br />
&nbsp;</span><span style="color: #008000;">#</span><span style="color: #008000;">开启&nbsp;excel</span><span style="color: #008000;"><br />
</span><span style="color: #000000;">&nbsp;</span><span style="color: #0000ff;">my</span><span style="color: #000000;">&nbsp;</span><span style="color: #800080;">$oBook</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;</span><span style="color: #800080;">$oExcel</span><span style="color: #000000;">-&gt;</span><span style="color: #000000;">Parse(</span><span style="color: #800080;">$sExcelName</span><span style="color: #000000;">,</span><span style="color: #800080;">$oFmtJ</span><span style="color: #000000;">);<br />
&nbsp;</span><span style="color: #008000;">#</span><span style="color: #008000;">根据&nbsp;sheet&nbsp;名称匹配&nbsp;</span><span style="color: #008000;"><br />
</span><span style="color: #000000;">&nbsp;</span><span style="color: #0000ff;">for</span><span style="color: #000000;">(</span><span style="color: #0000ff;">my</span><span style="color: #000000;">&nbsp;</span><span style="color: #800080;">$iSheet</span><span style="color: #000000;">=</span><span style="color: #800000;">0</span><span style="color: #000000;">;&nbsp;</span><span style="color: #800080;">$iSheet</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">&nbsp;</span><span style="color: #800080;">$oBook</span><span style="color: #000000;">-&gt;</span><span style="color: #000000;">{SheetCount}&nbsp;;&nbsp;</span><span style="color: #800080;">$iSheet</span><span style="color: #000000;">++</span><span style="color: #000000;">){<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">my</span><span style="color: #000000;">&nbsp;</span><span style="color: #800080;">$t_oWkS</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;</span><span style="color: #800080;">$oBook</span><span style="color: #000000;">-&gt;</span><span style="color: #000000;">{Worksheet}[</span><span style="color: #800080;">$iSheet</span><span style="color: #000000;">];<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">my</span><span style="color: #000000;">&nbsp;</span><span style="color: #800080;">$sWkSName</span><span style="color: #000000;">=</span><span style="color: #000000;">encode(</span><span style="color: #800080;">$coslCODE</span><span style="color: #000000;">,</span><span style="color: #000000;">decode(</span><span style="color: #800080;">$excelCODE</span><span style="color: #000000;">,</span><span style="color: #800080;">$t_oWkS</span><span style="color: #000000;">-&gt;</span><span style="color: #000000;">{Name}&nbsp;));<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">(</span><span style="color: #800080;">$sWkSName</span><span style="color: #000000;">=~/</span><span style="color: #800080;">$sSheetName</span><span style="color: #000000;">/</span><span style="color: #000000;">){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #800080;">$oWkS</span><span style="color: #000000;">=</span><span style="color: #800080;">$t_oWkS</span><span style="color: #000000;">;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">last</span><span style="color: #000000;">;<br />
&nbsp;&nbsp;&nbsp;}<br />
&nbsp;}<br />
<br />
<br />
&nbsp;</span><span style="color: #0000ff;">for</span><span style="color: #000000;">(</span><span style="color: #0000ff;">my</span><span style="color: #000000;">&nbsp;</span><span style="color: #800080;">$iR</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;</span><span style="color: #800080;">$oWkS</span><span style="color: #000000;">-&gt;</span><span style="color: #000000;">{MinRow}&nbsp;;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">defined</span><span style="color: #000000;">&nbsp;</span><span style="color: #800080;">$oWkS</span><span style="color: #000000;">-&gt;</span><span style="color: #000000;">{MaxRow}&nbsp;</span><span style="color: #000000;">&amp;&amp;</span><span style="color: #000000;">&nbsp;</span><span style="color: #800080;">$iR</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">&lt;=</span><span style="color: #000000;">&nbsp;</span><span style="color: #800080;">$oWkS</span><span style="color: #000000;">-&gt;</span><span style="color: #000000;">{MaxRow}&nbsp;;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #800080;">$iR</span><span style="color: #000000;">++</span><span style="color: #000000;">){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">my</span><span style="color: #000000;">&nbsp;</span><span style="color: #800080;">@arr_row</span><span style="color: #000000;">;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">for</span><span style="color: #000000;">(</span><span style="color: #0000ff;">my</span><span style="color: #000000;">&nbsp;</span><span style="color: #800080;">$iC</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;</span><span style="color: #800080;">$oWkS</span><span style="color: #000000;">-&gt;</span><span style="color: #000000;">{MinCol}&nbsp;;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">defined</span><span style="color: #000000;">&nbsp;</span><span style="color: #800080;">$oWkS</span><span style="color: #000000;">-&gt;</span><span style="color: #000000;">{MaxCol}&nbsp;</span><span style="color: #000000;">&amp;&amp;</span><span style="color: #000000;">&nbsp;</span><span style="color: #800080;">$iC</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">&lt;=</span><span style="color: #000000;">&nbsp;</span><span style="color: #800080;">$oWkS</span><span style="color: #000000;">-&gt;</span><span style="color: #000000;">{MaxCol}&nbsp;;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #800080;">$iC</span><span style="color: #000000;">++</span><span style="color: #000000;">){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #800080;">$oWkC</span><span style="color: #000000;">=</span><span style="color: #800080;">$oWkS</span><span style="color: #000000;">-&gt;</span><span style="color: #000000;">{Cells}[</span><span style="color: #800080;">$iR</span><span style="color: #000000;">][</span><span style="color: #800080;">$iC</span><span style="color: #000000;">];<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">my</span><span style="color: #000000;">&nbsp;</span><span style="color: #800080;">$col_value</span><span style="color: #000000;">=</span><span style="color: #000000; font-weight: bold;">""</span><span style="color: #000000;">;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #800080;">$col_value</span><span style="color: #000000;">=</span><span style="color: #000000;">encode(</span><span style="color: #800080;">$coslCODE</span><span style="color: #000000;">,</span><span style="color: #000000;">decode(</span><span style="color: #800080;">$excelCODE</span><span style="color: #000000;">,</span><span style="color: #800080;">$oWkC</span><span style="color: #000000;">-&gt;</span><span style="color: #000000;">Value)&nbsp;)&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">&nbsp;(</span><span style="color: #800080;">$oWkC</span><span style="color: #000000;">)&nbsp;;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">push</span><span style="color: #000000;">(</span><span style="color: #800080;">@arr_row</span><span style="color: #000000;">,</span><span style="color: #800080;">$col_value</span><span style="color: #000000;">);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">push</span><span style="color: #000000;">(</span><span style="color: #800080;">@arr_row</span><span style="color: #000000;">,</span><span style="color: #800080;">$iR</span><span style="color: #000000;">);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #800080;">$action_fun</span><span style="color: #000000;">-&gt;</span><span style="color: #000000;">(</span><span style="color: #800080;">@arr_row</span><span style="color: #000000;">);<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
}<br />
</span></div>
<br />
<div style="border: 1px solid #cccccc; padding: 4px 5px 4px 4px; background-color: #eeeeee; font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: #008000;">#</span><span style="color: #008000;">使用&nbsp;demo</span><span style="color: #008000;"><br />
</span><span style="color: #000000;">find&nbsp;</span><span style="color: #000000;">.</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">maxdepth&nbsp;</span><span style="color: #800000;">1</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">name&nbsp;</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000; font-weight: bold;">*xls</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">-</span><span style="color: #0000ff;">exec</span><span style="color: #000000;">&nbsp;perl&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">e&nbsp;</span><span style="color: #000000; font-weight: bold;">'</span><span style="color: #000000; font-weight: bold;"><br />
require("/home/xj_liukaiyi/src/perl/excel/excelUtil.pl");<br />
my&nbsp;$file=$ARGV[0];<br />
sub&nbsp;myRead{<br />
&nbsp;&nbsp;my&nbsp;$str="";<br />
&nbsp;&nbsp;foreach$tmp(@_){<br />
&nbsp;&nbsp;&nbsp;&nbsp;$str+"$tmp\t";<br />
&nbsp;&nbsp;}<br />
&nbsp;&nbsp;system&nbsp;"echo&nbsp;$str&nbsp;&gt;&gt;&nbsp;$file.data";<br />
}<br />
&amp;parse_excel("$file",0,\&amp;myRead);<br />
print&nbsp;"$file\n";<br />
</span><span style="color: #000000; font-weight: bold;">'</span><span style="color: #000000;">&nbsp;{}&nbsp;</span><span style="color: #000000;">\</span><span style="color: #000000;">;<br />
</span></div>
<br />
<br />
<br />
<img src ="http://www.blogjava.net/Skynet/aggbug/260234.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/Skynet/" target="_blank">刘凯毅</a> 2009-03-17 13:49 <a href="http://www.blogjava.net/Skynet/archive/2009/03/17/260234.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>perl 工具小脚本</title><link>http://www.blogjava.net/Skynet/archive/2009/03/02/257374.html</link><dc:creator>刘凯毅</dc:creator><author>刘凯毅</author><pubDate>Mon, 02 Mar 2009 09:51:00 GMT</pubDate><guid>http://www.blogjava.net/Skynet/archive/2009/03/02/257374.html</guid><wfw:comment>http://www.blogjava.net/Skynet/comments/257374.html</wfw:comment><comments>http://www.blogjava.net/Skynet/archive/2009/03/02/257374.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/Skynet/comments/commentRss/257374.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Skynet/services/trackbacks/257374.html</trackback:ping><description><![CDATA[<br />
<br />
工具小脚本<br />
<div style="border: 1px solid #cccccc; padding: 4px 5px 4px 4px; background-color: #eeeeee; font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: #008000;">#</span><span style="color: #008000;">!/bin/perl</span><span style="color: #008000;"><br />
</span><span style="color: #0000ff;">use</span><span style="color: #000000;">&nbsp;File</span><span style="color: #000000;">::</span><span style="color: #000000;">Find;<br />
</span><span style="color: #0000ff;">use</span><span style="color: #000000;">&nbsp;</span><span style="color: #0000ff;">Log</span><span style="color: #000000;">::</span><span style="color: #000000;">FileSimple;<br />
<br />
</span><span style="color: #008000;">#</span><span style="color: #008000;">use&nbsp;strict;<br />
#use&nbsp;warnings;<br />
<br />
#&nbsp;说明:&nbsp;<br />
#&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;遍历出&nbsp;"/cygdrive/c/Documents&nbsp;and&nbsp;Settings/Administrator/"&nbsp;&nbsp;<br />
#&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;满足&nbsp;"^.*\.txt$"&nbsp;添加文件<br />
#&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;并运行&nbsp;"ls&nbsp;-l&nbsp;$fileAllName&nbsp;"&nbsp;<br />
#&nbsp;&nbsp;&nbsp;&nbsp;运行日志&nbsp;./log<br />
#<br />
#&nbsp;perl&nbsp;this.pl&nbsp;&nbsp;<br />
#&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"ls&nbsp;-l&nbsp;$fileAllName&nbsp;"&nbsp;<br />
#&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"/cygdrive/c/Documents&nbsp;and&nbsp;Settings/Administrator/"&nbsp;&nbsp;<br />
#&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"^.*\.txt$"<br />
#&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;./log<br />
#<br />
#&nbsp;run_comm&nbsp;参数1&nbsp;替换说明：<br />
#&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$filePath&nbsp;&nbsp;为输入参数2，遍历根目录&nbsp;"/cygdrive/c/Documents&nbsp;and&nbsp;Settings/Administrator/"&nbsp;&nbsp;<br />
#&nbsp;&nbsp;&nbsp;&nbsp;$fileAllName&nbsp;为当前遍历，满足正则条件的&nbsp;全路径+文件名<br />
#&nbsp;&nbsp;&nbsp;&nbsp;$logicFileAllName&nbsp;&nbsp;为当前遍历，满足正则条件的&nbsp;逻辑路径+文件名<br />
#&nbsp;&nbsp;&nbsp;&nbsp;$logicFilePath&nbsp;为当前遍历，逻辑路径<br />
#&nbsp;&nbsp;&nbsp;&nbsp;$logicFileName&nbsp;文件名称<br />
#&nbsp;&nbsp;&nbsp;&nbsp;$logicFileExp&nbsp;&nbsp;文件后缀&nbsp;&nbsp;<br />
#&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;（test.txt&nbsp;文件&nbsp;&nbsp;<br />
#&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$logicFileName&nbsp;为&nbsp;test&nbsp;<br />
#&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$logicFileExp&nbsp;为&nbsp;txt<br />
#&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;）</span><span style="color: #008000;"><br />
</span><span style="color: #000000;"><br />
</span><span style="color: #0000ff;">my</span><span style="color: #000000;">&nbsp;</span><span style="color: #800080;">$run_comm</span><span style="color: #000000;">=</span><span style="color: #800080;">$ARGV</span><span style="color: #000000;">[</span><span style="color: #800000;">0</span><span style="color: #000000;">];<br />
</span><span style="color: #0000ff;">my</span><span style="color: #000000;">&nbsp;</span><span style="color: #800080;">$file_path</span><span style="color: #000000;">=</span><span style="color: #800080;">$ARGV</span><span style="color: #000000;">[</span><span style="color: #800000;">1</span><span style="color: #000000;">];<br />
</span><span style="color: #0000ff;">my</span><span style="color: #000000;">&nbsp;</span><span style="color: #800080;">$file_find_rex</span><span style="color: #000000;">=</span><span style="color: #800080;">$ARGV</span><span style="color: #000000;">[</span><span style="color: #800000;">2</span><span style="color: #000000;">];<br />
</span><span style="color: #0000ff;">my</span><span style="color: #000000;">&nbsp;</span><span style="color: #800080;">$logfile</span><span style="color: #000000;">=</span><span style="color: #800080;">$ARGV</span><span style="color: #000000;">[</span><span style="color: #800000;">3</span><span style="color: #000000;">];<br />
<br />
<br />
</span><span style="color: #0000ff;">my</span><span style="color: #000000;">&nbsp;</span><span style="color: #800080;">$log</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;new&nbsp;</span><span style="color: #0000ff;">Log</span><span style="color: #000000;">::</span><span style="color: #000000;">FileSimple(name</span><span style="color: #000000;">=&gt;</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000; font-weight: bold;">'</span><span style="color: #000000; font-weight: bold;">Log::FileSimple&nbsp;logs</span><span style="color: #000000; font-weight: bold;">'</span><span style="color: #000000;">,</span><span style="color: #000000;"><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;file&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000;">=&gt;</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000; font-weight: bold;">$logfile</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000;">,</span><span style="color: #000000;"><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mask&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000;">=&gt;</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">-</span><span style="color: #800000;">1</span><span style="color: #000000;">,</span><span style="color: #000000;"><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;autoflush&nbsp;</span><span style="color: #000000;">=&gt;</span><span style="color: #000000;">&nbsp;</span><span style="color: #800000;">0</span><span style="color: #000000;">,</span><span style="color: #000000;"><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;);<br />
<br />
</span><span style="color: #0000ff;">sub</span><span style="color: #000000;">&nbsp;fileThumb{<br />
&nbsp;</span><span style="color: #0000ff;">eval</span><span style="color: #000000;">{<br />
&nbsp;&nbsp;</span><span style="color: #800080;">$_tmp_run_comm</span><span style="color: #000000;">=</span><span style="color: #800080;">$run_comm</span><span style="color: #000000;">&nbsp;;<br />
&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">(&nbsp;</span><span style="color: #000000;">/</span><span style="color: #800080;">$file_find_rex</span><span style="color: #000000;">/</span><span style="color: #000000;">&nbsp;){<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #800080;">$fileNum</span><span style="color: #000000;">++</span><span style="color: #000000;">;<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #800080;">$_tmp_run_comm</span><span style="color: #000000;">=~</span><span style="color: #000000;">s</span><span style="color: #000000;">/\</span><span style="color: #800080;">$filePath</span><span style="color: #000000;">/</span><span style="color: #800080;">$file_path</span><span style="color: #000000;">/</span><span style="color: #000000;">g;<br />
&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">my</span><span style="color: #000000;">&nbsp;</span><span style="color: #800080;">$_file_all_name</span><span style="color: #000000;">=</span><span style="color: #800080;">$File</span><span style="color: #000000;">::</span><span style="color: #000000;">Find</span><span style="color: #000000;">::</span><span style="color: #000000;">name;<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #800080;">$_tmp_run_comm</span><span style="color: #000000;">=~</span><span style="color: #000000;">s</span><span style="color: #000000;">/\</span><span style="color: #800080;">$fileAllName</span><span style="color: #000000;">/</span><span style="color: #800080;">$_file_all_name</span><span style="color: #000000;">/</span><span style="color: #000000;">g;<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">my</span><span style="color: #000000;">&nbsp;</span><span style="color: #800080;">$_logic_file_all_name</span><span style="color: #000000;">=</span><span style="color: #800080;">$_file_all_name</span><span style="color: #000000;">;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #800080;">$_logic_file_all_name</span><span style="color: #000000;">=~</span><span style="color: #000000;">s</span><span style="color: #000000;">/</span><span style="color: #800080;">$file_path</span><span style="color: #000000;">//</span><span style="color: #000000;">g;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #800080;">$_logic_file_all_name</span><span style="color: #000000;">=~</span><span style="color: #000000;">s</span><span style="color: #000000;">/^\</span><span style="color: #000000;">s</span><span style="color: #000000;">*\.//</span><span style="color: #000000;">g;<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #800080;">$_tmp_run_comm</span><span style="color: #000000;">=~</span><span style="color: #000000;">s</span><span style="color: #000000;">/\</span><span style="color: #800080;">$logicFileAllName</span><span style="color: #000000;">/\.\/</span><span style="color: #800080;">$_logic_file_all_name</span><span style="color: #000000;">/</span><span style="color: #000000;">g;<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">(</span><span style="color: #800080;">$_logic_file_all_name</span><span style="color: #000000;">=~/^</span><span style="color: #000000;">(</span><span style="color: #000000;">.*</span><span style="color: #000000;">)</span><span style="color: #000000;">\/</span><span style="color: #000000;">([</span><span style="color: #000000;">^\/</span><span style="color: #000000;">]</span><span style="color: #000000;">*</span><span style="color: #000000;">)</span><span style="color: #000000;">\.</span><span style="color: #000000;">([</span><span style="color: #000000;">^\.</span><span style="color: #000000;">]</span><span style="color: #000000;">*</span><span style="color: #000000;">)$</span><span style="color: #000000;">/</span><span style="color: #000000;">){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">my</span><span style="color: #000000;">&nbsp;</span><span style="color: #800080;">$_logic_file_path</span><span style="color: #000000;">=</span><span style="color: #000000;">$</span><span style="color: #800000;">1</span><span style="color: #000000;">;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">my</span><span style="color: #000000;">&nbsp;</span><span style="color: #800080;">$_logic_file_name</span><span style="color: #000000;">=</span><span style="color: #000000;">$</span><span style="color: #800000;">2</span><span style="color: #000000;">;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">my</span><span style="color: #000000;">&nbsp;</span><span style="color: #800080;">$_logic_file_exp</span><span style="color: #000000;">=</span><span style="color: #000000;">$</span><span style="color: #800000;">3</span><span style="color: #000000;">;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #800080;">$_tmp_run_comm</span><span style="color: #000000;">=~</span><span style="color: #000000;">s</span><span style="color: #000000;">/\</span><span style="color: #800080;">$logicFilePath</span><span style="color: #000000;">/\.\/</span><span style="color: #800080;">$_logic_file_path</span><span style="color: #000000;">/</span><span style="color: #000000;">g;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #800080;">$_tmp_run_comm</span><span style="color: #000000;">=~</span><span style="color: #000000;">s</span><span style="color: #000000;">/\</span><span style="color: #800080;">$logicFileName</span><span style="color: #000000;">/</span><span style="color: #800080;">$_logic_file_name</span><span style="color: #000000;">/</span><span style="color: #000000;">g;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #800080;">$_tmp_run_comm</span><span style="color: #000000;">=~</span><span style="color: #000000;">s</span><span style="color: #000000;">/\</span><span style="color: #800080;">$logicFileExp</span><span style="color: #000000;">/</span><span style="color: #800080;">$_logic_file_exp</span><span style="color: #000000;">/</span><span style="color: #000000;">g;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000;">#</span><span style="color: #008000;">print&nbsp;$_tmp_run_comm,"\n";</span><span style="color: #008000;"><br />
</span><span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">my</span><span style="color: #000000;">&nbsp;</span><span style="color: #800080;">@return</span><span style="color: #000000;">=</span><span style="color: #0000ff;">eval</span><span style="color: #000000;">{</span><span style="color: #0000ff;">system</span><span style="color: #000000;">(</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000; font-weight: bold;">$_tmp_run_comm&nbsp;2&gt;&amp;1&nbsp;\|echo&nbsp;\$\?&nbsp;</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000;">)};</span><span style="color: #000000;"><br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">&nbsp;(&nbsp;</span><span style="color: #800080;">$return</span><span style="color: #000000;">[(</span><span style="color: #800080;">@return</span><span style="color: #000000;">-</span><span style="color: #800000;">1</span><span style="color: #000000;">)]&nbsp;</span><span style="color: #000000;">!=</span><span style="color: #000000;">&nbsp;</span><span style="color: #800000;">0</span><span style="color: #000000;">&nbsp;)&nbsp;{&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #800080;">$log</span><span style="color: #000000;">-&gt;</span><span style="color: #0000ff;">log</span><span style="color: #000000;">(message</span><span style="color: #000000;">=&gt;</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000; font-weight: bold;">success($fileNum):$_file_all_name</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000;">);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span><span style="color: #0000ff;">else</span><span style="color: #000000;">{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #800080;">$log</span><span style="color: #000000;">-&gt;</span><span style="color: #0000ff;">log</span><span style="color: #000000;">(message</span><span style="color: #000000;">=&gt;</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000; font-weight: bold;">error($fileNum):$_file_all_name</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000;">);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;}<br />
&nbsp;}<br />
}<br />
<br />
<br />
find(</span><span style="color: #000000;">\&amp;</span><span style="color: #000000;">fileThumb</span><span style="color: #000000;">,</span><span style="color: #800080;">$file_path</span><span style="color: #000000;">);<br />
</span></div>
<br />
<img src ="http://www.blogjava.net/Skynet/aggbug/257374.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/Skynet/" target="_blank">刘凯毅</a> 2009-03-02 17:51 <a href="http://www.blogjava.net/Skynet/archive/2009/03/02/257374.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title> soap (java,perl,要写代码 还不过 100 char) </title><link>http://www.blogjava.net/Skynet/archive/2009/03/02/257264.html</link><dc:creator>刘凯毅</dc:creator><author>刘凯毅</author><pubDate>Sun, 01 Mar 2009 16:00:00 GMT</pubDate><guid>http://www.blogjava.net/Skynet/archive/2009/03/02/257264.html</guid><wfw:comment>http://www.blogjava.net/Skynet/comments/257264.html</wfw:comment><comments>http://www.blogjava.net/Skynet/archive/2009/03/02/257264.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/Skynet/comments/commentRss/257264.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Skynet/services/trackbacks/257264.html</trackback:ping><description><![CDATA[<br />
<strong>可能最简单的 soap </strong>哦！<br />
服务器为 java tomcat <br />
下载服务器：http://www.apache.org/dist/ws/<br />
&nbsp;&nbsp; <a href="http://www.apache.org/dist/ws/axis/">axis/</a>   为java <br />
&nbsp;&nbsp; <a href="http://www.apache.org/dist/ws/axis-c/">axis-c/</a>  &nbsp;&nbsp; 为 c <br />
<br />
1.我这下载的 axis 1_4 版本 ，解压 /webapps/axis&nbsp; 放到 tomcat 的webapps <br />
启动tomcat（这就不修改任何，如有需要 该 web.xml 等配置了）<a href="http://suaihuang.blog.163.com/blog/?clsId=fks_087067083084086071085086074064084081085065086081087&amp;class=#" style="font-size: 12px;" onclick="NEBlog.gPrevBlog.oBlogList._oUpdownMenu.openBlog('blog/static/307422712007552499407', event);return false;"> 参考 &gt;&gt;</a><br />
&nbsp;&nbsp;&nbsp; blog 主 还有很多介绍 axis 大家可以 看看<a hidefocus="true" href="http://suaihuang.blog.163.com/blog/" onclick="">&nbsp; 日志</a> &gt; 其下的 "学习" <br />
<br />
直接写个文件 <strong>HelloWorld.jws</strong> 放到 %TOMCAT_HOME%"webapps"axis
<div style="border: 1px solid #cccccc; padding: 4px 5px 4px 4px; background-color: #eeeeee; font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: #0000ff;">public</span><span style="color: #000000;">&nbsp;</span><span style="color: #0000ff;">class</span><span style="color: #000000;">&nbsp;HelloWorld&nbsp;{&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">public</span><span style="color: #000000;">&nbsp;String&nbsp;sayHello()&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">return</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">HELLO&nbsp;soap!</span><span style="color: #000000;">"</span><span style="color: #000000;">;&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;<br />
}&nbsp; <br />
</span></div>
<br />
等不及 可以使用 看看<br />
http://127.0.0.1:8080/axis/HelloWorld.jws?method=sayHello<br />
结果 ：<br />
<div style="border: 1px solid #cccccc; padding: 4px 5px 4px 4px; background-color: #eeeeee; font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: #0000ff;">&lt;</span><span style="color: #800000;">soapenv:Envelope</span><span style="color: #0000ff;">&gt;</span><span style="color: #000000;"><br />
</span><span style="color: #0000ff;">&lt;</span><span style="color: #800000;">soapenv:Body</span><span style="color: #0000ff;">&gt;</span><span style="color: #000000;"><br />
</span><span style="color: #0000ff;">&lt;</span><span style="color: #800000;">sayHelloResponse&nbsp;</span><span style="color: #ff0000;">soapenv:encodingStyle</span><span style="color: #0000ff;">="http://schemas.xmlsoap.org/soap/encoding/"</span><span style="color: #0000ff;">&gt;</span><span style="color: #000000;"><br />
</span><span style="color: #0000ff;">&lt;</span><span style="color: #800000;">sayHelloReturn&nbsp;</span><span style="color: #ff0000;">xsi:type</span><span style="color: #0000ff;">="xsd:string"</span><span style="color: #0000ff;">&gt;</span><span style="color: #000000;">HELLO&nbsp;soap!</span><span style="color: #0000ff;">&lt;/</span><span style="color: #800000;">sayHelloReturn</span><span style="color: #0000ff;">&gt;</span><span style="color: #000000;"><br />
</span><span style="color: #0000ff;">&lt;/</span><span style="color: #800000;">sayHelloResponse</span><span style="color: #0000ff;">&gt;</span><span style="color: #000000;"><br />
</span><span style="color: #0000ff;">&lt;/</span><span style="color: #800000;">soapenv:Body</span><span style="color: #0000ff;">&gt;</span><span style="color: #000000;"><br />
</span><span style="color: #0000ff;">&lt;/</span><span style="color: #800000;">soapenv:Envelope</span><span style="color: #0000ff;">&gt;</span></div>
<br />
<br />
客户段<br />
perl cpan &gt;&gt; install&nbsp; SOAP::Lite<br />
<div style="border: 1px solid #cccccc; padding: 4px 5px 4px 4px; background-color: #eeeeee; font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: #008000;">#</span><span style="color: #008000;">!perl&nbsp;-w</span><span style="color: #008000;"><br />
</span><span style="color: #0000ff;">use</span><span style="color: #000000;">&nbsp;SOAP</span><span style="color: #000000;">::</span><span style="color: #000000;">Lite;<br />
</span><span style="color: #0000ff;">print</span><span style="color: #000000;">&nbsp;SOAP</span><span style="color: #000000;">::</span><span style="color: #000000;">Lite<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000;">-&gt;</span><span style="color: #000000;">&nbsp;proxy(</span><span style="color: #000000; font-weight: bold;">'</span><span style="color: #000000; font-weight: bold;">http://127.0.0.1:8080/axis/HelloWorld.jws</span><span style="color: #000000; font-weight: bold;">'</span><span style="color: #000000;">)<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000;">-&gt;</span><span style="color: #000000;">&nbsp;uri(</span><span style="color: #000000; font-weight: bold;">'</span><span style="color: #000000; font-weight: bold;">http://127.0.0.1:8080/axis/HelloWorld.jws</span><span style="color: #000000; font-weight: bold;">'</span><span style="color: #000000;">)<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000;">-&gt;</span><span style="color: #000000;">&nbsp;sayHello()<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000;">-&gt;</span><span style="color: #000000;">&nbsp;result;<br />
</span></div>
结果： <span style="color: #000000;">HELLO&nbsp;soap！</span><br />
<br />
<br />
<br />
<br />
<img src ="http://www.blogjava.net/Skynet/aggbug/257264.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/Skynet/" target="_blank">刘凯毅</a> 2009-03-02 00:00 <a href="http://www.blogjava.net/Skynet/archive/2009/03/02/257264.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Memcached 对话 Google ProtocolBuffers (perl)</title><link>http://www.blogjava.net/Skynet/archive/2009/02/26/256804.html</link><dc:creator>刘凯毅</dc:creator><author>刘凯毅</author><pubDate>Thu, 26 Feb 2009 05:45:00 GMT</pubDate><guid>http://www.blogjava.net/Skynet/archive/2009/02/26/256804.html</guid><wfw:comment>http://www.blogjava.net/Skynet/comments/256804.html</wfw:comment><comments>http://www.blogjava.net/Skynet/archive/2009/02/26/256804.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/Skynet/comments/commentRss/256804.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Skynet/services/trackbacks/256804.html</trackback:ping><description><![CDATA[<br />
<br />
&nbsp;
看看我这张 web&nbsp; 系统架构图，那就知道 <strong>使用统一存储格式的好处了。<br />
&nbsp;
在这种结构中你就单纯使用 java ，或 php 某一种单一语言描述格式，存储你集群交互的数据吗！？使用</strong><strong>ProtocolBuffers</strong> 吧，<strong>Google 已经有 现成的api来帮你扩展了。</strong><br />
<strong>
<br />
参考：</strong>http://blog.csdn.net/lcj8/archive/2009/02/17/3900157.aspx
<p><img src="http://p.blog.csdn.net/images/p_blog_csdn_net/wanghao72214/EntryImages/20090131/1224059455_ddvip_6170.jpg" alt="" width="289" height="263" /></p>
<br />
<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;
作为 <strong>Memcached </strong>就是为集群使用，那么作为在缓存存储的数据我想也应该适用与各种环境，这时候 数据结构协议 <strong>Google ProtocolBuffers </strong><br />
<strong>参考：</strong>http://code.google.com/apis/protocolbuffers/docs/overview.html<br />
<strong>其他语言：</strong>http://code.google.com/p/protobuf/wiki/OtherLanguages<br />
（可适用与多种语言，<br />
&nbsp;&nbsp;&nbsp; javascript 读取缓存中的数据 ,你可以想象下你的 web服务开发 的将来！）<br />
<br />
<br />
<br />
目前学习perl 中 就先上个这的代码：<br />
<strong>参考：</strong><br />
http://search.cpan.org/~gariev/Google-ProtocolBuffers-0.08/lib/Google/ProtocolBuffers.pm#___top
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: rgb(0, 128, 0);">#</span><span style="color: rgb(0, 128, 0);">!/bin/perl&nbsp;-w</span><span style="color: rgb(0, 128, 0);"><br />
</span><span style="color: rgb(0, 0, 255);">use</span><span style="color: rgb(0, 0, 0);">&nbsp;Cache</span><span style="color: rgb(0, 0, 0);">::</span><span style="color: rgb(0, 0, 0);">Memcached;<br />
</span><span style="color: rgb(0, 0, 255);">use</span><span style="color: rgb(0, 0, 0);">&nbsp;Google</span><span style="color: rgb(0, 0, 0);">::</span><span style="color: rgb(0, 0, 0);">ProtocolBuffers;<br />
<span style="color: rgb(8, 255, 69);"><span style="color: rgb(34, 182, 43);">#开启 memd</span></span><br />
</span><span style="color: rgb(0, 0, 255);">my</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(128, 0, 128);">$memd</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;new&nbsp;Cache</span><span style="color: rgb(0, 0, 0);">::</span><span style="color: rgb(0, 0, 0);">Memcached{servers&nbsp;</span><span style="color: rgb(0, 0, 0);">=&gt;</span><span style="color: rgb(0, 0, 0);">&nbsp;[</span><span style="color: rgb(0, 0, 0); font-weight: bold;">'</span><span style="color: rgb(0, 0, 0); font-weight: bold;">10.0.2.15:11211</span><span style="color: rgb(0, 0, 0); font-weight: bold;">'</span><span style="color: rgb(0, 0, 0);">]&nbsp;};<br />
<br />
<span style="color: rgb(29, 136, 56);">#声明 缓存 存储 protocol 格式</span><br />
</span><span style="color: rgb(0, 0, 255);">my</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(128, 0, 128);">$key</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0); font-weight: bold;">'</span><span style="color: rgb(0, 0, 0); font-weight: bold;">test</span><span style="color: rgb(0, 0, 0); font-weight: bold;">'</span><span style="color: rgb(0, 0, 0);">;<br />
Google</span><span style="color: rgb(0, 0, 0);">::</span><span style="color: rgb(0, 0, 0);">ProtocolBuffers</span><span style="color: rgb(0, 0, 0);">-&gt;</span><span style="color: rgb(0, 0, 0);">parse(</span><span style="color: rgb(0, 0, 0); font-weight: bold;">"</span><span style="color: rgb(0, 0, 0); font-weight: bold;"><br />
&nbsp;&nbsp;message&nbsp;Person{<br />
&nbsp;&nbsp;&nbsp;&nbsp;required&nbsp;int32&nbsp;id&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=1;<br />
&nbsp;&nbsp;&nbsp;&nbsp;required&nbsp;string&nbsp;name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=2;<br />
&nbsp;&nbsp;}<br />
</span><span style="color: rgb(0, 0, 0); font-weight: bold;">"</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);">{create_accessors</span><span style="color: rgb(0, 0, 0);">=&gt;</span><span style="color: rgb(128, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">});<br />
<br />
</span><span style="color: rgb(0, 0, 255);">my</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(128, 0, 128);">$data</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">Person</span><span style="color: rgb(0, 0, 0);">-&gt;</span><span style="color: rgb(0, 0, 0);">encode({<br />
&nbsp;&nbsp;id</span><span style="color: rgb(0, 0, 0);">=&gt;</span><span style="color: rgb(128, 0, 0);">123</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);"><br />
&nbsp;&nbsp;name</span><span style="color: rgb(0, 0, 0);">=&gt;</span><span style="color: rgb(0, 0, 0); font-weight: bold;">'</span><span style="color: rgb(0, 0, 0); font-weight: bold;">liukaiyi</span><span style="color: rgb(0, 0, 0); font-weight: bold;">'</span><span style="color: rgb(0, 0, 0);"><br />
});<br />
<br />
<span style="color: rgb(53, 142, 75);">#缓存存储</span><br />
</span><span style="color: rgb(128, 0, 128);">$memd</span><span style="color: rgb(0, 0, 0);">-&gt;</span><span style="color: rgb(0, 0, 0);">add(</span><span style="color: rgb(128, 0, 128);">$key</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 0);">=&gt;</span><span style="color: rgb(128, 0, 128);">$data</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(128, 0, 0);">3600</span><span style="color: rgb(0, 0, 0);">);<br />
<br />
</span><span style="color: rgb(0, 128, 0);">#</span><span style="color: rgb(0, 128, 0);">######################################################################</span><span style="color: rgb(0, 128, 0);"><br />
</span><span style="color: rgb(0, 0, 0);"><br />
<br />
</span><span style="color: rgb(0, 0, 255);">my</span>&nbsp;<span style="color: rgb(128, 0, 128);">$memd</span>&nbsp;<span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;new&nbsp;Cache</span><span style="color: rgb(0, 0, 0);">::</span><span style="color: rgb(0, 0, 0);">Memcached{servers&nbsp;</span><span style="color: rgb(0, 0, 0);">=&gt;</span><span style="color: rgb(0, 0, 0);">&nbsp;[</span><span style="color: rgb(0, 0, 0); font-weight: bold;">'</span><span style="color: rgb(0, 0, 0); font-weight: bold;">10.0.2.15:11211</span><span style="color: rgb(0, 0, 0); font-weight: bold;">'</span><span style="color: rgb(0, 0, 0);">]&nbsp;};</span><br />
<span style="color: rgb(0, 0, 255);">my</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(128, 0, 128);">$person</span><span style="color: rgb(0, 0, 0);">;{<br />
&nbsp; <span style="color: rgb(21, 140, 51);">#从缓存中取出</span><br />
&nbsp;&nbsp;</span><span style="color: rgb(128, 0, 128);">$person</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;Person</span><span style="color: rgb(0, 0, 0);">-&gt;</span><span style="color: rgb(0, 0, 0);">decode(</span><span style="color: rgb(128, 0, 128);">$memd</span><span style="color: rgb(0, 0, 0);">-&gt;</span><span style="color: rgb(0, 0, 0);">get(</span><span style="color: rgb(128, 0, 128);">$key</span><span style="color: rgb(0, 0, 0);">));<br />
}<br />
<br />
</span><span style="color: rgb(0, 0, 255);">print</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(128, 0, 128);">$person</span><span style="color: rgb(0, 0, 0);">-&gt;</span><span style="color: rgb(0, 0, 0);">id</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0); font-weight: bold;">"</span><span style="color: rgb(0, 0, 0); font-weight: bold;">-</span><span style="color: rgb(0, 0, 0); font-weight: bold;">"</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(128, 0, 128);">$person</span><span style="color: rgb(0, 0, 0);">-&gt;</span><span style="color: rgb(0, 0, 0);">name;<br />
<br />
</span></div>
&nbsp;<br />
<br />
<br />
结果：<br />
&nbsp; 123-liukaiyi<br />
<br />
<br />
<img src ="http://www.blogjava.net/Skynet/aggbug/256804.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/Skynet/" target="_blank">刘凯毅</a> 2009-02-26 13:45 <a href="http://www.blogjava.net/Skynet/archive/2009/02/26/256804.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>memcached 使用（perl）</title><link>http://www.blogjava.net/Skynet/archive/2009/02/25/256642.html</link><dc:creator>刘凯毅</dc:creator><author>刘凯毅</author><pubDate>Wed, 25 Feb 2009 08:23:00 GMT</pubDate><guid>http://www.blogjava.net/Skynet/archive/2009/02/25/256642.html</guid><wfw:comment>http://www.blogjava.net/Skynet/comments/256642.html</wfw:comment><comments>http://www.blogjava.net/Skynet/archive/2009/02/25/256642.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/Skynet/comments/commentRss/256642.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Skynet/services/trackbacks/256642.html</trackback:ping><description><![CDATA[&nbsp; <br />
&nbsp; 这大体上可以看出，服务器端口缓存技术。<br />
<br />
&nbsp; memcached 官方：http://www.danga.com/memcached/<br />
&nbsp; 安装前，先安装 <a href="http://www.monkey.org/%7Eprovos/libevent/">libevent</a><br />
&nbsp; 其上为 linux 软件一般安装，看他们readme文档 <br />
&nbsp; $&gt;memcached -d -u nobody -m 512 127.0.0.1 -p 11211<br />
&nbsp; <br />
&nbsp; 如果有异常，<br />
&nbsp; <strong><span style="color: rgb(53, 24, 255);">ln -s /usr/local/lib/libevent-1.4.so.2 /lib/libevent-1.4.so.2<br />
&nbsp; 参考&nbsp; </span></strong>http://blog.chinaunix.net/u2/70049/showart_1665279.html<br />
<strong><span style="color: rgb(53, 24, 255);">&nbsp; </span></strong>我这就使用 <strong>perl</strong> 语言了，<br />
&nbsp;&nbsp; 其他语言参考 http://code.google.com/p/memcached/wiki/Clients<br />
<br />
&nbsp;&nbsp; perl 使用 cpan&gt; install <span style="color: rgb(0, 0, 0);">Cache</span><span style="color: rgb(0, 0, 0);">::</span><span style="color: rgb(0, 0, 0);">Memcached ;<strong>#会使用 perl 我就不说了</strong></span><br />
代码说明：不停对 key 为test 的值进行递增 &nbsp; <br />
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: rgb(0, 128, 0);">#</span><span style="color: rgb(0, 128, 0);">!/bin/perl&nbsp;-w</span><span style="color: rgb(0, 128, 0);"><br />
</span><span style="color: rgb(0, 0, 255);">use</span><span style="color: rgb(0, 0, 0);">&nbsp;Cache</span><span style="color: rgb(0, 0, 0);">::</span><span style="color: rgb(0, 0, 0);">Memcached;<br />
<br />
</span><span style="color: rgb(0, 0, 255);">my</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(128, 0, 128);">$memd</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;new&nbsp;Cache</span><span style="color: rgb(0, 0, 0);">::</span><span style="color: rgb(0, 0, 0);">Memcached{servers&nbsp;</span><span style="color: rgb(0, 0, 0);">=&gt;</span><span style="color: rgb(0, 0, 0);">&nbsp;[</span><span style="color: rgb(0, 0, 0); font-weight: bold;">'</span><span style="color: rgb(0, 0, 0); font-weight: bold;">127.0.0.1:11211</span><span style="color: rgb(0, 0, 0); font-weight: bold;">'</span><span style="color: rgb(0, 0, 0);">]&nbsp;};<br />
</span><span style="color: rgb(0, 0, 255);">my</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(128, 0, 128);">$key</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 0); font-weight: bold;">'</span><span style="color: rgb(0, 0, 0); font-weight: bold;">test</span><span style="color: rgb(0, 0, 0); font-weight: bold;">'</span><span style="color: rgb(0, 0, 0);">;<br />
</span><span style="color: rgb(128, 0, 128);">$memd</span><span style="color: rgb(0, 0, 0);">-&gt;</span><span style="color: rgb(0, 0, 0);">add(</span><span style="color: rgb(128, 0, 128);">$key</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 0);">=&gt;</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(128, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(128, 0, 0);">3600</span><span style="color: rgb(0, 0, 0);">)&nbsp;or&nbsp;</span><span style="color: rgb(0, 0, 255);">warn</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 0); font-weight: bold;">'</span><span style="color: rgb(0, 0, 0); font-weight: bold;">Alread&nbsp;added</span><span style="color: rgb(0, 0, 0); font-weight: bold;">'</span><span style="color: rgb(0, 0, 0);">;<br />
</span><span style="color: rgb(0, 0, 255);">while</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(128, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">){<br />
&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">print</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(128, 0, 128);">$memd</span><span style="color: rgb(0, 0, 0);">-&gt;</span><span style="color: rgb(0, 0, 0);">get(</span><span style="color: rgb(128, 0, 128);">$key</span><span style="color: rgb(0, 0, 0);">)</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0); font-weight: bold;">"</span><span style="color: rgb(0, 0, 0); font-weight: bold;">\n</span><span style="color: rgb(0, 0, 0); font-weight: bold;">"</span><span style="color: rgb(0, 0, 0);">;<br />
&nbsp;&nbsp;</span><span style="color: rgb(128, 0, 128);">$memd</span><span style="color: rgb(0, 0, 0);">-&gt;</span><span style="color: rgb(0, 0, 0);">incr(</span><span style="color: rgb(128, 0, 128);">$key</span><span style="color: rgb(0, 0, 0);">)&nbsp;or&nbsp;</span><span style="color: rgb(0, 0, 255);">warn</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 0); font-weight: bold;">'</span><span style="color: rgb(0, 0, 0); font-weight: bold;">FAIL!</span><span style="color: rgb(0, 0, 0); font-weight: bold;">'</span><span style="color: rgb(0, 0, 0);">;<br />
}</span><span style="color: rgb(0, 0, 0);"><br />
</span></div>
<strong></strong>
<br />
使用 telnet 127.0.0.1 11211<br />
&nbsp; &nbsp;&nbsp; $&gt; get&nbsp; test <br />
&nbsp; &nbsp;&nbsp; VALUE test 0 2<br />
&nbsp; &nbsp;&nbsp; <strong><span style="color: rgb(248, 0, 0);">97</span></strong> <strong>#这就是我们递增的值,当然你使用什么语言取都是一样的 <br />
</strong>&nbsp; &nbsp;&nbsp; END <br />
<br />
<img src ="http://www.blogjava.net/Skynet/aggbug/256642.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/Skynet/" target="_blank">刘凯毅</a> 2009-02-25 16:23 <a href="http://www.blogjava.net/Skynet/archive/2009/02/25/256642.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>perl file find </title><link>http://www.blogjava.net/Skynet/archive/2009/02/23/256367.html</link><dc:creator>刘凯毅</dc:creator><author>刘凯毅</author><pubDate>Mon, 23 Feb 2009 15:55:00 GMT</pubDate><guid>http://www.blogjava.net/Skynet/archive/2009/02/23/256367.html</guid><wfw:comment>http://www.blogjava.net/Skynet/comments/256367.html</wfw:comment><comments>http://www.blogjava.net/Skynet/archive/2009/02/23/256367.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/Skynet/comments/commentRss/256367.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Skynet/services/trackbacks/256367.html</trackback:ping><description><![CDATA[使用 File::Find
<div style="border: 1px solid #cccccc; padding: 4px 5px 4px 4px; background-color: #eeeeee; font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: #0000ff;">use</span><span style="color: #000000;">&nbsp;File</span><span style="color: #000000;">::</span><span style="color: #000000;">Find;<br />
</span><span style="color: #0000ff;">use</span><span style="color: #000000;">&nbsp;</span><span style="color: #0000ff;">Time</span><span style="color: #000000;">::</span><span style="color: #000000;">Piece;<br />
<br />
<br />
</span><span style="color: #800080;">$timeOneDay</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;</span><span style="color: #800000;">86400</span><span style="color: #000000;">;<br />
</span><span style="color: #800080;">$dayMultipler</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;</span><span style="color: #800000;">1</span><span style="color: #000000;">;<br />
<br />
</span><span style="color: #800080;">$ByteCount</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;</span><span style="color: #800000;">0</span><span style="color: #000000;">;<br />
</span><span style="color: #800080;">$fileAll</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;</span><span style="color: #800000;">0</span><span style="color: #000000;">;<br />
</span><span style="color: #800080;">$fileJpg</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;</span><span style="color: #800000;">0</span><span style="color: #000000;">;<br />
</span><span style="color: #800080;">$fileYes</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;</span><span style="color: #800000;">0</span><span style="color: #000000;">;<br />
</span><span style="color: #800080;">$pathToTra</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000; font-weight: bold;">.</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000;">;<br />
<br />
</span><span style="color: #800080;">$gt</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;</span><span style="color: #0000ff;">localtime</span><span style="color: #000000;">;<br />
</span><span style="color: #800080;">$t1</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;</span><span style="color: #800080;">$gt</span><span style="color: #000000;">-&gt;</span><span style="color: #000000;">epoch;<br />
find(</span><span style="color: #000000;">\&amp;</span><span style="color: #000000;">fileThumb</span><span style="color: #000000;">,</span><span style="color: #000000;">&nbsp;</span><span style="color: #800080;">$pathToTra</span><span style="color: #000000;">);<br />
</span><span style="color: #800080;">$gt</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;</span><span style="color: #0000ff;">localtime</span><span style="color: #000000;">;<br />
</span><span style="color: #800080;">$t2</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;</span><span style="color: #800080;">$gt</span><span style="color: #000000;">-&gt;</span><span style="color: #000000;">epoch;<br />
<br />
</span><span style="color: #0000ff;">print</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000; font-weight: bold;">Total&nbsp;KByte:&nbsp;</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000;">.</span><span style="color: #000000;">(</span><span style="color: #800080;">$ByteCount</span><span style="color: #000000;">/</span><span style="color: #800000;">1024</span><span style="color: #000000;">)</span><span style="color: #000000;">.</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000; font-weight: bold;">\n</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000;">;<br />
</span><span style="color: #0000ff;">print</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000; font-weight: bold;">Total&nbsp;Scan:&nbsp;&nbsp;</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000;">.</span><span style="color: #800080;">$fileAll</span><span style="color: #000000;">.</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000; font-weight: bold;">\n</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000;">;<br />
</span><span style="color: #0000ff;">print</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000; font-weight: bold;">Total&nbsp;Jpeg:&nbsp;&nbsp;</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000;">.</span><span style="color: #800080;">$fileJpg</span><span style="color: #000000;">.</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000; font-weight: bold;">\n</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000;">;<br />
</span><span style="color: #0000ff;">print</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000; font-weight: bold;">Total&nbsp;Match:&nbsp;</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000;">.</span><span style="color: #800080;">$fileYes</span><span style="color: #000000;">.</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000; font-weight: bold;">\n</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000;">;<br />
</span><span style="color: #0000ff;">print</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000; font-weight: bold;">Total&nbsp;TimeCost:&nbsp;</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000;">.</span><span style="color: #000000;">(</span><span style="color: #800080;">$t2</span><span style="color: #000000;">-</span><span style="color: #800080;">$t1</span><span style="color: #000000;">)</span><span style="color: #000000;">.</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000; font-weight: bold;">\n</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000;">;<br />
<br />
</span><span style="color: #0000ff;">sub</span><span style="color: #000000;">&nbsp;fileThumb<br />
{<br />
&nbsp;&nbsp;&nbsp;</span><span style="color: #800080;">$fileAll</span><span style="color: #000000;">++</span><span style="color: #000000;">;<br />
&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">&nbsp;((</span><span style="color: #000000;">/.*\.</span><span style="color: #000000;">jpg$</span><span style="color: #000000;">/</span><span style="color: #000000;">)&nbsp;)<br />
&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #800080;">$fileJpg</span><span style="color: #000000;">++</span><span style="color: #000000;">;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">my</span><span style="color: #000000;">&nbsp;</span><span style="color: #800080;">$lt</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;</span><span style="color: #800000;">0</span><span style="color: #000000;">;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #800080;">$lt</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;</span><span style="color: #0000ff;">localtime</span><span style="color: #000000;">;<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">my</span><span style="color: #000000;">&nbsp;(</span><span style="color: #800080;">$dev</span><span style="color: #000000;">,</span><span style="color: #000000;">&nbsp;</span><span style="color: #800080;">$ino</span><span style="color: #000000;">,</span><span style="color: #000000;">&nbsp;</span><span style="color: #800080;">$mode</span><span style="color: #000000;">,</span><span style="color: #000000;">&nbsp;</span><span style="color: #800080;">$nlink</span><span style="color: #000000;">,</span><span style="color: #000000;">&nbsp;</span><span style="color: #800080;">$uid</span><span style="color: #000000;">,</span><span style="color: #000000;">&nbsp;</span><span style="color: #800080;">$gid</span><span style="color: #000000;">,</span><span style="color: #000000;">&nbsp;</span><span style="color: #800080;">$rdev</span><span style="color: #000000;">,</span><span style="color: #000000;">&nbsp;</span><span style="color: #800080;">$size</span><span style="color: #000000;">,</span><span style="color: #000000;">&nbsp;</span><span style="color: #800080;">$atime</span><span style="color: #000000;">,</span><span style="color: #000000;">&nbsp;</span><span style="color: #800080;">$mtime</span><span style="color: #000000;">,</span><span style="color: #000000;">&nbsp;</span><span style="color: #800080;">$ctime</span><span style="color: #000000;">,</span><span style="color: #000000;">&nbsp;</span><span style="color: #800080;">$blksize</span><span style="color: #000000;">,</span><span style="color: #000000;">&nbsp;</span><span style="color: #800080;">$blocks</span><span style="color: #000000;">)&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;</span><span style="color: #0000ff;">stat</span><span style="color: #000000;">(</span><span style="color: #800080;">$_</span><span style="color: #000000;">)&nbsp;&nbsp;or&nbsp;</span><span style="color: #0000ff;">die</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000; font-weight: bold;">Unable&nbsp;to&nbsp;stat&nbsp;$_\n</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000;">;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">&nbsp;(&nbsp;</span><span style="color: #800080;">$mtime</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">&nbsp;(</span><span style="color: #800080;">$lt</span><span style="color: #000000;">-&gt;</span><span style="color: #000000;">epoch&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">&nbsp;</span><span style="color: #800080;">$timeOneDay</span><span style="color: #000000;">*</span><span style="color: #800080;">$dayMultipler</span><span style="color: #000000;">)&nbsp;)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">print</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000; font-weight: bold;">[&nbsp;$fileYes&nbsp;]</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000;">.</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000; font-weight: bold;">$File::Find::name</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000;">;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">print</span><span style="color: #000000;">&nbsp;</span><span style="color: #800080;">$size</span><span style="color: #000000;">.</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000; font-weight: bold;">&nbsp;</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000;">.</span><span style="color: #800080;">$ctime</span><span style="color: #000000;">.</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000; font-weight: bold;">&nbsp;</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000;">.</span><span style="color: #800080;">$lt</span><span style="color: #000000;">-&gt;</span><span style="color: #000000;">epoch</span><span style="color: #000000;">.</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000; font-weight: bold;">\n</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000;">;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #800080;">$ByteCount</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">+=</span><span style="color: #000000;">&nbsp;</span><span style="color: #800080;">$size</span><span style="color: #000000;">;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #800080;">$fileYes</span><span style="color: #000000;">++</span><span style="color: #000000;">;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;}<br />
}</span></div>
<br />
<br />
<br />
&nbsp;<br />
<br />
<img src ="http://www.blogjava.net/Skynet/aggbug/256367.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/Skynet/" target="_blank">刘凯毅</a> 2009-02-23 23:55 <a href="http://www.blogjava.net/Skynet/archive/2009/02/23/256367.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>log4j perl 错误日志提取</title><link>http://www.blogjava.net/Skynet/archive/2009/02/19/255445.html</link><dc:creator>刘凯毅</dc:creator><author>刘凯毅</author><pubDate>Thu, 19 Feb 2009 05:01:00 GMT</pubDate><guid>http://www.blogjava.net/Skynet/archive/2009/02/19/255445.html</guid><wfw:comment>http://www.blogjava.net/Skynet/comments/255445.html</wfw:comment><comments>http://www.blogjava.net/Skynet/archive/2009/02/19/255445.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/Skynet/comments/commentRss/255445.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Skynet/services/trackbacks/255445.html</trackback:ping><description><![CDATA[<br />
日志<br />
<div style="border: 1px solid #cccccc; padding: 4px 5px 4px 4px; background-color: #eeeeee; font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: #008000;">#</span><span style="color: #008000;">!/bin/perl</span><span style="color: #008000;"><br />
</span><span style="color: #0000ff;">use</span><span style="color: #000000;">&nbsp;Encode&nbsp;;<br />
</span><span style="color: #0000ff;">open</span><span style="color: #000000;">(NOTESFILES</span><span style="color: #000000;">,</span><span style="color: #800080;">$ARGV</span><span style="color: #000000;">[</span><span style="color: #800000;">0</span><span style="color: #000000;">]);<br />
<br />
</span><span style="color: #0000ff;">my</span><span style="color: #000000;">&nbsp;</span><span style="color: #800080;">%errorMeganotes</span><span style="color: #000000;">;<br />
<br />
</span><span style="color: #0000ff;">print</span><span style="color: #000000;"> </span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000; font-weight: bold;">&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000;">,</span><span style="color: #800080;">$ARGV</span><span style="color: #000000;">[</span><span style="color: #800000;">0</span><span style="color: #000000;">]</span><span style="color: #000000;">,</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000; font-weight: bold;">&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;\n</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000;">;<br />
<br />
</span><span style="color: #0000ff;">while</span><span style="color: #000000;">&nbsp;(</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">NOTESFILES</span><span style="color: #000000;">&gt;</span><span style="color: #000000;">)&nbsp;{<br />
&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">(&nbsp;</span><span style="color: #800080;">$_</span><span style="color: #000000;">=~/^</span><span style="color: #000000;">(</span><span style="color: #000000;">\</span><span style="color: #000000;">d{</span><span style="color: #800000;">4</span><span style="color: #000000;">}</span><span style="color: #000000;">-\</span><span style="color: #000000;">d{</span><span style="color: #800000;">2</span><span style="color: #000000;">}</span><span style="color: #000000;">-\</span><span style="color: #000000;">d{</span><span style="color: #800000;">2</span><span style="color: #000000;">}</span><span style="color: #000000;">\</span><span style="color: #000000;">s</span><span style="color: #000000;">\</span><span style="color: #000000;">d{</span><span style="color: #800000;">2</span><span style="color: #000000;">}</span><span style="color: #000000;">:\</span><span style="color: #000000;">d{</span><span style="color: #800000;">2</span><span style="color: #000000;">}</span><span style="color: #000000;">:\</span><span style="color: #000000;">d{</span><span style="color: #800000;">2</span><span style="color: #000000;">})</span><span style="color: #000000;">\</span><span style="color: #000000;">s</span><span style="color: #000000;">+</span><span style="color: #000000;">ERROR</span><span style="color: #000000;">\</span><span style="color: #000000;">s</span><span style="color: #000000;">+</span><span style="color: #000000;">(</span><span style="color: #000000;">.*</span><span style="color: #000000;">)</span><span style="color: #000000;">\</span><span style="color: #000000;">s</span><span style="color: #000000;">/</span><span style="color: #000000;">g&nbsp;){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">(</span><span style="color: #800080;">$errorMeganotes</span><span style="color: #000000;">{$</span><span style="color: #800000;">2</span><span style="color: #000000;">}){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">push</span><span style="color: #000000;">&nbsp;@{</span><span style="color: #800080;">$errorMeganotes</span><span style="color: #000000;">{$</span><span style="color: #800000;">2</span><span style="color: #000000;">}}</span><span style="color: #000000;">,</span><span style="color: #000000;">$</span><span style="color: #800000;">1</span><span style="color: #000000;">;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span><span style="color: #0000ff;">else</span><span style="color: #000000;">{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #800080;">$errorMeganotes</span><span style="color: #000000;">{$</span><span style="color: #800000;">2</span><span style="color: #000000;">}</span><span style="color: #000000;">=</span><span style="color: #000000;">[$</span><span style="color: #800000;">1</span><span style="color: #000000;">];<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;}<br />
}<br />
<br />
</span><span style="color: #0000ff;">for</span><span style="color: #000000;">(</span><span style="color: #0000ff;">keys</span><span style="color: #000000;">&nbsp;</span><span style="color: #800080;">%errorMeganotes</span><span style="color: #000000;">){<br />
&nbsp;&nbsp;</span><span style="color: #0000ff;">my</span><span style="color: #000000;">&nbsp;</span><span style="color: #800080;">$tmp_keys</span><span style="color: #000000;">=</span><span style="color: #800080;">$_</span><span style="color: #000000;">;<br />
&nbsp;&nbsp;</span><span style="color: #0000ff;">my</span><span style="color: #000000;">&nbsp;</span><span style="color: #800080;">@tmp_array</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;@{</span><span style="color: #800080;">$errorMeganotes</span><span style="color: #000000;">{</span><span style="color: #800080;">$tmp_keys</span><span style="color: #000000;">}};<br />
&nbsp;&nbsp;</span><span style="color: #0000ff;">print</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000; font-weight: bold;">error&nbsp;number&nbsp;:&gt;&gt;</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000;">,</span><span style="color: #0000ff;">scalar</span><span style="color: #000000;">(</span><span style="color: #800080;">@tmp_array</span><span style="color: #000000;">)</span><span style="color: #000000;">,</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000; font-weight: bold;">&lt;&lt;\n</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000;">,</span><span style="color: #000000;">encode(</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000; font-weight: bold;">GBK</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000;">,</span><span style="color: #000000;">decode(</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000; font-weight: bold;">UTF-8</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000;">,</span><span style="color: #800080;">$tmp_keys</span><span style="color: #000000;">))</span><span style="color: #000000;">,</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000; font-weight: bold;">\n</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000;">,</span><span style="color: #0000ff;">join</span><span style="color: #000000;">(</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000; font-weight: bold;">,\t</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000;">,</span><span style="color: #800080;">@tmp_array</span><span style="color: #000000;">)</span><span style="color: #000000;">,</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000; font-weight: bold;">\n\n\n</span><span style="color: #000000; font-weight: bold;">"</span><span style="color: #000000;">;<br />
}<br />
</span></div>
<br />
<br />
sh<br />
<div style="border: 1px solid #cccccc; padding: 4px 5px 4px 4px; background-color: #eeeeee; font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: #008000;">#</span><span style="color: #008000;">!/bin/sh</span><span style="color: #008000;"><br />
</span><span style="color: #000000;">nowDate</span><span style="color: #000000;">=</span><span style="color: #000000;">$(date&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">d&nbsp;</span><span style="color: #800000;">'</span><span style="color: #800000;">-1&nbsp;day</span><span style="color: #800000;">'</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">+%</span><span style="color: #000000;">Y</span><span style="color: #000000;">-%</span><span style="color: #000000;">m</span><span style="color: #000000;">-%</span><span style="color: #000000;">d);<br />
echo&nbsp;$nowDate<br />
<br />
perl&nbsp;</span><span style="color: #000000;">/</span><span style="color: #000000;">data</span><span style="color: #000000;">/</span><span style="color: #000000;">apps</span><span style="color: #000000;">/</span><span style="color: #000000;">shell</span><span style="color: #000000;">/</span><span style="color: #000000;">meganotesErrorLog.pl&nbsp;</span><span style="color: #000000;">/</span><span style="color: #000000;">data</span><span style="color: #000000;">/</span><span style="color: #000000;">apps</span><span style="color: #000000;">/</span><span style="color: #000000;">meganotes</span><span style="color: #000000;">/</span><span style="color: #000000;">tomcat</span><span style="color: #000000;">/</span><span style="color: #000000;">logs</span><span style="color: #000000;">/</span><span style="color: #000000;">app</span><span style="color: #000000;">/</span><span style="color: #000000;">app.log.$nowDate&nbsp;</span><span style="color: #000000;">&gt;</span><span style="color: #000000;">&nbsp;&nbsp;_tmp_$nowDate&nbsp;;<br />
perl&nbsp;</span><span style="color: #000000;">/</span><span style="color: #000000;">data</span><span style="color: #000000;">/</span><span style="color: #000000;">apps</span><span style="color: #000000;">/</span><span style="color: #000000;">shell</span><span style="color: #000000;">/</span><span style="color: #000000;">meganotesErrorLog.pl&nbsp;</span><span style="color: #000000;">/</span><span style="color: #000000;">data</span><span style="color: #000000;">/</span><span style="color: #000000;">apps</span><span style="color: #000000;">/</span><span style="color: #000000;">schedule</span><span style="color: #000000;">/</span><span style="color: #000000;">tomcat</span><span style="color: #000000;">/</span><span style="color: #000000;">logs</span><span style="color: #000000;">/</span><span style="color: #000000;">app</span><span style="color: #000000;">/</span><span style="color: #000000;">app.log.$nowDate&nbsp;&nbsp;</span><span style="color: #000000;">&gt;&gt;</span><span style="color: #000000;">&nbsp;_tmp_$nowDate&nbsp;;<br />
<br />
<br />
mail&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">s&nbsp;$nowDate</span><span style="color: #000000;">-</span><span style="color: #000000;">ERROR</span><span style="color: #000000;">-</span><span style="color: #000000;">log&nbsp;&nbsp;my@mail.com&nbsp;&nbsp;</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">&nbsp;&nbsp;_tmp_$nowDate;<br />
rm&nbsp;_tmp_$nowDate&nbsp;;<br />
</span></div>
<br />
结果：<br />
&gt;&gt;&gt;&gt;&gt;&gt;&gt;/data/apps/meganotes/tomcat/logs/app/app.log.2009-02-18&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;<br />
error number :&gt;&gt;2&lt;&lt;<br />
MusicActionOpLogProxy:142 - music.popularTime=[Invalid field value for field "music.popularTime".]<br />
2009-02-18 15:53:54,&nbsp;&nbsp; &nbsp;2009-02-18 16:00:12<br />
。。。。。。<br />
<br />
<br />
<br />
<img src ="http://www.blogjava.net/Skynet/aggbug/255445.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/Skynet/" target="_blank">刘凯毅</a> 2009-02-19 13:01 <a href="http://www.blogjava.net/Skynet/archive/2009/02/19/255445.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>使用 awk 一样 使用 perl 并 她可爱的正则 </title><link>http://www.blogjava.net/Skynet/archive/2009/02/17/255158.html</link><dc:creator>刘凯毅</dc:creator><author>刘凯毅</author><pubDate>Tue, 17 Feb 2009 09:39:00 GMT</pubDate><guid>http://www.blogjava.net/Skynet/archive/2009/02/17/255158.html</guid><wfw:comment>http://www.blogjava.net/Skynet/comments/255158.html</wfw:comment><comments>http://www.blogjava.net/Skynet/archive/2009/02/17/255158.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/Skynet/comments/commentRss/255158.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Skynet/services/trackbacks/255158.html</trackback:ping><description><![CDATA[<br />
参考：<br />
&nbsp; http://my.huhoo.net/archives/2007/08/perl_1.html<br />
<br />
<strong>简单的 </strong><br />
&nbsp;&nbsp; echo "tt" |perl&nbsp; -ne&nbsp; 'print $_ '<br />
<strong>多行</strong><br />
&nbsp;&nbsp; find . -type f |perl&nbsp; -ne&nbsp; 'print $1 $_ if $_=~ /(.*)flv/'<strong><br />
</strong>
<strong>限定行数</strong><br />
&nbsp;&nbsp; find . -type f |perl&nbsp; -ne&nbsp; 'print $_ if $_=~ /.*flv/ &amp;&amp; <strong>$tmp++</strong>&lt;10 &amp;&amp; <strong>$tmp</strong>&gt;4' <br />
&nbsp;&nbsp;&nbsp; #当然shell&gt;&gt; find . -type f |grep ".*flv" |sed -n '5,10p' 和上面是一样的 <br />
&nbsp;&nbsp;&nbsp; # 不过 你看那&nbsp; 其中使用 $1 等正则重定向 ,哈哈 <br />
结果大体上 <br />
./test3/0.flv<br />
./flvplayer.swf<br />
./test.flv<br />
./0.flv<br />
<br />
<br />
<br />
<br />
perl -h <br />
&nbsp; -e program&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; one line of program (several -e's allowed, omit programfile)<br />
&nbsp; -n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; assume "while (&lt;&gt;) { ... }" loop around program<br />
&nbsp; -p&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; assume loop like -n but print line also, like sed<br />
<br />
<br />
<br />
<br />
<img src ="http://www.blogjava.net/Skynet/aggbug/255158.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/Skynet/" target="_blank">刘凯毅</a> 2009-02-17 17:39 <a href="http://www.blogjava.net/Skynet/archive/2009/02/17/255158.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>perl log4j  分析日志</title><link>http://www.blogjava.net/Skynet/archive/2009/02/17/255116.html</link><dc:creator>刘凯毅</dc:creator><author>刘凯毅</author><pubDate>Tue, 17 Feb 2009 07:50:00 GMT</pubDate><guid>http://www.blogjava.net/Skynet/archive/2009/02/17/255116.html</guid><wfw:comment>http://www.blogjava.net/Skynet/comments/255116.html</wfw:comment><comments>http://www.blogjava.net/Skynet/archive/2009/02/17/255116.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/Skynet/comments/commentRss/255116.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Skynet/services/trackbacks/255116.html</trackback:ping><description><![CDATA[<br />
<br />
普通的 log4j 日志 ；<br />
当然 特殊要求 特殊处理 。<br />
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: rgb(0, 128, 0);">#</span><span style="color: rgb(0, 128, 0);">!/bin/perl</span><span style="color: rgb(0, 128, 0);"><br />
</span><span style="color: rgb(0, 0, 255);">open</span><span style="color: rgb(0, 0, 0);">(FILES</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0); font-weight: bold;">"</span><span style="color: rgb(0, 0, 0); font-weight: bold;">/data/apps/schedule/tomcat/logs/app/app.log.2009-02-17</span><span style="color: rgb(0, 0, 0); font-weight: bold;">"</span><span style="color: rgb(0, 0, 0);">);<br />
</span><span style="color: rgb(0, 0, 255);">while</span><span style="color: rgb(0, 0, 0);">&nbsp;(</span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">FILES</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);">)&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">next</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 0);">!/^\</span><span style="color: rgb(0, 0, 0);">d{</span><span style="color: rgb(128, 0, 0);">4</span><span style="color: rgb(0, 0, 0);">}</span><span style="color: rgb(0, 0, 0);">-\</span><span style="color: rgb(0, 0, 0);">d{</span><span style="color: rgb(128, 0, 0);">2</span><span style="color: rgb(0, 0, 0);">}</span><span style="color: rgb(0, 0, 0);">-\</span><span style="color: rgb(0, 0, 0);">d{</span><span style="color: rgb(128, 0, 0);">2</span><span style="color: rgb(0, 0, 0);">}</span><span style="color: rgb(0, 0, 0);">\</span><span style="color: rgb(0, 0, 0);">s</span><span style="color: rgb(0, 0, 0);">\</span><span style="color: rgb(0, 0, 0);">d{</span><span style="color: rgb(128, 0, 0);">2</span><span style="color: rgb(0, 0, 0);">}</span><span style="color: rgb(0, 0, 0);">:\</span><span style="color: rgb(0, 0, 0);">d{</span><span style="color: rgb(128, 0, 0);">2</span><span style="color: rgb(0, 0, 0);">}</span><span style="color: rgb(0, 0, 0);">:\</span><span style="color: rgb(0, 0, 0);">d{</span><span style="color: rgb(128, 0, 0);">2</span><span style="color: rgb(0, 0, 0);">}</span><span style="color: rgb(0, 0, 0);">\</span><span style="color: rgb(0, 0, 0);">s</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);">ERROR</span><span style="color: rgb(0, 0, 0);">\</span><span style="color: rgb(0, 0, 0);">s</span><span style="color: rgb(0, 0, 0);">+/</span><span style="color: rgb(0, 0, 0);">;<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(128, 0, 128);">$_</span><span style="color: rgb(0, 0, 0);">=~/</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">.*-</span><span style="color: rgb(0, 0, 0);">){</span><span style="color: rgb(128, 0, 0);">3</span><span style="color: rgb(0, 0, 0);">}(</span><span style="color: rgb(0, 0, 0);">.*?</span><span style="color: rgb(0, 0, 0);">)</span><span style="color: rgb(0, 0, 0);">:</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">.*</span><span style="color: rgb(0, 0, 0);">)$</span><span style="color: rgb(0, 0, 0);">/</span><span style="color: rgb(0, 0, 0);">g){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(128, 0, 128);">$error</span><span style="color: rgb(0, 0, 0);">{$</span><span style="color: rgb(128, 0, 0);">2</span><span style="color: rgb(0, 0, 0);">}</span><span style="color: rgb(0, 0, 0);">++</span><span style="color: rgb(0, 0, 0);">&nbsp;;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}</span><span style="color: rgb(0, 0, 255);">elsif</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(128, 0, 128);">$_</span><span style="color: rgb(0, 0, 0);">=~/</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 0);">.*-</span><span style="color: rgb(0, 0, 0);">){</span><span style="color: rgb(128, 0, 0);">3</span><span style="color: rgb(0, 0, 0);">}(</span><span style="color: rgb(0, 0, 0);">.*</span><span style="color: rgb(0, 0, 0);">)</span><span style="color: rgb(0, 0, 0);">/</span><span style="color: rgb(0, 0, 0);">g&nbsp;){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(128, 0, 128);">$error</span><span style="color: rgb(0, 0, 0);">{$</span><span style="color: rgb(128, 0, 0);">2</span><span style="color: rgb(0, 0, 0);">}</span><span style="color: rgb(0, 0, 0);">++</span><span style="color: rgb(0, 0, 0);">&nbsp;;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp; <br />
&nbsp;&nbsp;&nbsp; 。。。。。<br />
&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;<br />
</span><span style="color: rgb(0, 0, 255);">print</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 0); font-weight: bold;">"</span><span style="color: rgb(0, 0, 0); font-weight: bold;">$_:&nbsp;$error{$_}\n</span><span style="color: rgb(0, 0, 0); font-weight: bold;">"</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">for</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 255);">keys</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(128, 0, 128);">%error</span><span style="color: rgb(0, 0, 0);">);<br />
</span></div>
<br />
&nbsp;java.net.SocketTimeoutException: 4<br />
&nbsp;test1 illegal!: 4<br />
&nbsp;cd illegal!: 4<br />
&nbsp;test2 illegal!: 4<br />
&nbsp;MusicAlbum not exists: 5<br />
&nbsp;Not Found Any File: 14<br />
&nbsp;java.net.ConnectException: 3<br />
&nbsp;Album not exists: 2<br />
&nbsp;。。。<br />
<br />
<br />
<img src ="http://www.blogjava.net/Skynet/aggbug/255116.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/Skynet/" target="_blank">刘凯毅</a> 2009-02-17 15:50 <a href="http://www.blogjava.net/Skynet/archive/2009/02/17/255116.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>