<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>浏忙大爆炸 &#187; Perl</title>
	<atom:link href="http://blog.waterlin.org/articles/tag/perl/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.waterlin.org</link>
	<description>源于理工科男的烂笔头情结</description>
	<lastBuildDate>Fri, 03 Feb 2012 08:35:37 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
		<item>
		<title>Bugzilla 在 Windows 下的简易安装</title>
		<link>http://blog.waterlin.org/articles/install-bugzilla-under-windows-server.html</link>
		<comments>http://blog.waterlin.org/articles/install-bugzilla-under-windows-server.html#comments</comments>
		<pubDate>Thu, 30 Sep 2010 09:21:35 +0000</pubDate>
		<dc:creator>waterlin</dc:creator>
				<category><![CDATA[技术]]></category>
		<category><![CDATA[GTD]]></category>
		<category><![CDATA[Perl]]></category>

		<guid isPermaLink="false">http://blog.waterlin.org/articles/install-bugzilla-under-windows-server.html</guid>
		<description><![CDATA[苦于没有空闲的 Linux 服务器了，只好用 Windows 来搭一个 Bugzilla 服务器。浏忙绪绪我今天就给大家介绍一下 Windows 下 Bugzilla 的简易安装与配置。 一次性简易安装 Bugzilla Windows 下安装 Bugzilla 可以看官方文档，不过这里推荐使用一次性简易完全安装包，懒人有懒福嘛。的确，对于小公司来说，没有什么需要精心配置的东西。 配置 SendMail 的替代品 Bugzilla 如果不能发邮件通知更新，那查找 bug 的最新状况，将是非常痛苦的一件事情。 但是 Bugzilla 默认下用 SMTP 的话，不能带 SMTP TLS 校验的东西，可以通过安装 Perl 包 Email::Send::SMTP 来解决这个问题。 不过，在这里，我更推荐用伪装 SendMail 的方法来解决这个问题。 在 Windows 下，有一个很简单的方法来伪装 SendMail 发邮件的方式，它实际上还是使用 SMTP 的方式。 如果你的 Bugzilla 安装在 D:\Bugzilla ，则你把假 SendMail 解压放到目录 D:\usr\lib 里即可，注意驱动器要相同。 [...]]]></description>
			<content:encoded><![CDATA[<p>苦于没有空闲的 Linux 服务器了，只好用 Windows 来搭一个 <a href="http://www.bugzilla.org/">Bugzilla</a> 服务器。浏忙绪绪我今天就给大家介绍一下 Windows 下 Bugzilla 的简易安装与配置。</p>
<div class="outline-3">
<h3 id="sec-1.1">一次性简易安装 Bugzilla</h3>
<div class="outline-text-3">
<p>Windows 下安装 Bugzilla 可以看<a href="https://wiki.mozilla.org/Bugzilla:Win32Install">官方文档</a>，不过这里推荐使用<a href="https://wiki.mozilla.org/Bugzilla:Win32InstallPackages">一次性简易完全安装包</a>，懒人有懒福嘛。的确，对于小公司来说，没有什么需要精心配置的东西。</p>
</p></div>
</p></div>
<div class="outline-3">
<h3 id="sec-1.2">配置 SendMail 的替代品</h3>
<div class="outline-text-3">
<p>Bugzilla 如果不能发邮件通知更新，那查找 bug 的最新状况，将是非常痛苦的一件事情。</p>
<p>但是 Bugzilla 默认下用 SMTP 的话，不能带 SMTP TLS 校验的东西，可以通过安装 Perl 包 <a href="http://www.dawood.in/bugzilla_alerts_using_gmail.html">Email::Send::SMTP</a> 来解决这个问题。</p>
<p>不过，在这里，我更推荐用伪装 SendMail 的方法来解决这个问题。</p>
<p>在 Windows 下，有一个<a href="http://www.glob.com.au/sendmail/">很简单的方法来伪装 SendMail 发邮件的方式</a>，它实际上还是使用 SMTP 的方式。</p>
<p>如果你的 Bugzilla 安装在 D:\Bugzilla ，则你把假 SendMail 解压放到目录 D:\usr\lib 里即可，注意驱动器要相同。</p>
<p>配置好了以后，记得从命令行测试一下假的 SendMail 配置是否正确：</p>
<pre>
D:\usr\lib&gt;sendmail.exe -t
You must configure the smtp_server and default_domain<span> in</span>:
  D:\usr\lib\sendmail.ini
  or
  HKLM\Software\Sendmail
</pre>
<p>上面这个例子，就是提示配置不正确。</p>
<p>这样，就可以用 Gmail 来发提醒邮件了。不过要注意，如果要配置用 Gmail 来发邮件，要在 Bugzilla 的管理面板里有关邮件的设置里，把 smtpserver 设置为 smtp.gmail.com:587 即可。</p>
</p></div>
</p></div>
<div class="outline-3">
<h3 id="sec-1.3">简单设置 Bugzilla</h3>
<div class="outline-text-3">
<p>记得，要设置 urlbase，否则用户一注册，收到的邮件里，都没有网址的前缀了 :)</p>
</p></div>
</p></div>
<div class="outline-3">
<h3 id="sec-1.4">后续话题</h3>
<div class="outline-text-3">
<p>以后再介绍更多小技巧，呵，敬请期待。</p>
</p></div>
</p></div>
]]></content:encoded>
			<wfw:commentRss>http://blog.waterlin.org/articles/install-bugzilla-under-windows-server.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>补充：查询本地已经安装了哪些 Perl 模块</title>
		<link>http://blog.waterlin.org/articles/more-about-check-installed-modules-of-perl.html</link>
		<comments>http://blog.waterlin.org/articles/more-about-check-installed-modules-of-perl.html#comments</comments>
		<pubDate>Fri, 25 Sep 2009 06:27:32 +0000</pubDate>
		<dc:creator>waterlin</dc:creator>
				<category><![CDATA[技术]]></category>
		<category><![CDATA[Perl]]></category>

		<guid isPermaLink="false">http://blog.waterlin.org/articles/more-about-check-installed-modules-of-perl.html</guid>
		<description><![CDATA[补充一下昨天总结的查询本地已经安装了哪些 Perl 模块的方法，还有两种方法可以用： 在 shell 里运行下面的语句： $ perl -mSmart::Comments -el 如果提示了类似下面的错误， Can&#8217;t locate Smart/Comments.pm in @INC (@INC contains: c:/strawberry/perl/lib c:/strawberry/perl/site/lib .). 则表明你的 Perl 并没有安装这个模块。如果已经安装了该模块，则不会发生任何事情。 还可以用相类似的方法来测试，比如说，直接从 shell 里运行一下 Perl 的 use 命令： $ perl -e "use Smart::Comments;" 直接在后面使用 use 语句，如果这个模块存在的话，则不会报错；如果这个模块不存在的话，会提示出错信息。 如果在 Perl 代码里需要查询、获得已安装的模块信息，则可以使用 ExtUtils::Installed 模块。]]></description>
			<content:encoded><![CDATA[<p>补充一下昨天总结的<a href="http://blog.waterlin.org/articles/what-modules-are-already-installed-on-my-system.html">查询本地已经安装了哪些 Perl 模块的方法</a>，还有两种方法可以用：</p>
<ol>
<li>在 shell 里运行下面的语句：</p>
<pre>
$ perl -mSmart::Comments -el
</pre>
<p> 如果提示了类似下面的错误， Can&#8217;t locate Smart/Comments.pm in @INC (@INC contains: c:/strawberry/perl/lib c:/strawberry/perl/site/lib .).
<p>则表明你的 Perl 并没有安装这个模块。如果已经安装了该模块，则不会发生任何事情。</p>
<p>还可以用相类似的方法来测试，比如说，直接从 shell 里运行一下 Perl 的 use 命令：</p>
<pre>
$ perl -e <span>"use Smart::Comments;"</span>
</pre>
<p>直接在后面使用 use 语句，如果这个模块存在的话，则不会报错；如果这个模块不存在的话，会提示出错信息。</p>
</li>
<li>如果在 Perl 代码里需要查询、获得已安装的模块信息，则可以使用 <a href="http://search.cpan.org/~yves/ExtUtils-Install-1.54/lib/ExtUtils/Installed.pm">ExtUtils::Installed</a> 模块。</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://blog.waterlin.org/articles/more-about-check-installed-modules-of-perl.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>查询本地已经安装了哪些 Perl 模块</title>
		<link>http://blog.waterlin.org/articles/what-modules-are-already-installed-on-my-system.html</link>
		<comments>http://blog.waterlin.org/articles/what-modules-are-already-installed-on-my-system.html#comments</comments>
		<pubDate>Thu, 24 Sep 2009 10:48:57 +0000</pubDate>
		<dc:creator>waterlin</dc:creator>
				<category><![CDATA[技术]]></category>
		<category><![CDATA[Perl]]></category>

		<guid isPermaLink="false">http://blog.waterlin.org/articles/what-modules-are-already-installed-on-my-system.html</guid>
		<description><![CDATA[要查询本地已经安装了哪些 Perl 模块 (module)，我们可以用命令 $ perldoc perllocal 来查询，这个命令会显示出你系统里所有已经安装上的模块名称、安装路径等信息。 同样，如果是 ActivePerl，可以用命令 C:\&#62;ppm query 来检查已安装的模块信息。]]></description>
			<content:encoded><![CDATA[<p>要查询<a href="http://www.cpan.org/misc/cpan-faq.html#How_installed_modules">本地已经安装了哪些 Perl 模块</a> (module)，我们可以用命令</p>
<pre>
$ perldoc perllocal
</pre>
<p>来查询，这个命令会显示出你系统里所有已经安装上的模块名称、安装路径等信息。</p>
<p>同样，如果是 ActivePerl，可以用命令</p>
<pre>
C:<span>\&gt;</span>ppm query
</pre>
<p>来检查已安装的模块信息。</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.waterlin.org/articles/what-modules-are-already-installed-on-my-system.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>几个比较好用的 Perl 模块</title>
		<link>http://blog.waterlin.org/articles/perl-modules-about-timestamp-excel-comments-cpp.html</link>
		<comments>http://blog.waterlin.org/articles/perl-modules-about-timestamp-excel-comments-cpp.html#comments</comments>
		<pubDate>Wed, 23 Sep 2009 09:23:43 +0000</pubDate>
		<dc:creator>waterlin</dc:creator>
				<category><![CDATA[技术]]></category>
		<category><![CDATA[Perl]]></category>

		<guid isPermaLink="false">http://blog.waterlin.org/articles/perl-modules-about-timestamp-excel-comments-cpp.html</guid>
		<description><![CDATA[最近用 Perl 写了不少自动化测试工具，用到了一些模块，有几个觉得挺好的，记录下来，以后说不定还有需要用到呢。 Smart::Comments Smart comments 提供了一个调试与追踪代码的简单方法，可以打印一个变量值，也可以追踪、显示一个循环的进度等。 最巧妙的是，当你完成了程序的编写，不需要这些调试代码的时候，只需要注释掉 use Smart::Comments; 这行就可以了。下次还需要再次调试代码的时候，不需要再添加一遍追踪代码，只要把上面那行代码重新激活就可以了。 如果你不在程序里用上面的语句显式的激活 smart comments，我们也可以在运行脚本的时候，显示地激活 smart comments 模块： $ perl -MSmart::Comments $application.pl 给 Perl 提供类似 C++ 宏的功能 如果有一段代码，需要在多个地方重复用到，但是写成函数却并不是很合适，这个时候，最好的办法，是用类似于 C++ 的宏定义，在需要的地方插入这个宏即可。可以用 Filter::cpp 这个模块来实现，安装这个模块后，用起来和 C++ 的宏就没有什么区别了。 在 Perl 里操作 Excel 文件 现在很多测试用的测试用例 (test case) 以及测试报告都是用 Excel 来写的，要完成自动化测试，Perl 脚本最好能够自动从 Excel 读入数据、并在相应位置上记录测试结果。与这相关的工作，可以用下面的模块来完成： 如果我们需要读入 (parse) 一个已有的 Excel 文件，可以使用 Spreadsheet::ParseExcel，适用于 Excel 95-2003 [...]]]></description>
			<content:encoded><![CDATA[<p>最近用 Perl 写了不少自动化测试工具，用到了一些模块，有几个觉得挺好的，记录下来，以后说不定还有需要用到呢。</p>
<ol>
<li><a href="http://search.cpan.org/~chorny/Smart-Comments-1.0.4/lib/Smart/Comments.pm">Smart::Comments</a>
<p><a href="http://search.cpan.org/~chorny/Smart-Comments-1.0.4/lib/Smart/Comments.pm">Smart comments</a> 提供了一个调试与追踪代码的简单方法，可以打印一个变量值，也可以追踪、显示一个循环的进度等。</p>
<p>最巧妙的是，当你完成了程序的编写，不需要这些调试代码的时候，只需要注释掉</p>
<pre>
<span>use</span> <span>Smart::Comments</span>;
</pre>
<p> 这行就可以了。下次还需要再次调试代码的时候，不需要再添加一遍追踪代码，只要把上面那行代码重新激活就可以了。
<p>如果你不在程序里用上面的语句显式的激活 smart comments，我们也可以在运行脚本的时候，显示地激活 smart comments 模块：</p>
<pre>
$ perl -MSmart::Comments $application.pl
</pre>
</li>
<li>给 Perl 提供类似 C++ 宏的功能
<p>如果有一段代码，需要在多个地方重复用到，但是写成函数却并不是很合适，这个时候，最好的办法，是用类似于 C++ 的宏定义，在需要的地方插入这个宏即可。可以用 <a href="http://search.cpan.org/~pmqs/Filter-1.37/lib/Filter/cpp.pm">Filter::cpp</a> 这个模块来实现，安装这个模块后，用起来和 C++ 的宏就没有什么区别了。</p>
</li>
<li>在 Perl 里操作 Excel 文件
<p>现在很多测试用的测试用例 (test case) 以及测试报告都是用 Excel 来写的，要完成自动化测试，Perl 脚本最好能够自动从 Excel 读入数据、并在相应位置上记录测试结果。与这相关的工作，可以用下面的模块来完成：</p>
<p>如果我们需要读入 (parse) 一个已有的 Excel 文件，可以使用 <a href="http://search.cpan.org/~jmcnamara/Spreadsheet-ParseExcel-0.54/lib/Spreadsheet/ParseExcel.pm">Spreadsheet::ParseExcel</a>，适用于 Excel 95-2003 版本。如果你用的是 Excel 2007 版本，则你需要用 <a href="http://search.cpan.org/~dmow/Spreadsheet-XLSX/lib/Spreadsheet/XLSX.pm">Spreadsheet::XLSX</a> 这个模块。</p>
<p>如果我们需要创建一个全新的 Excel 文件并写入数据，我们可以用 <a href="http://search.cpan.org/~jmcnamara/Spreadsheet-WriteExcel/lib/Spreadsheet/WriteExcel.pm">Spreadsheet::WriteExcel</a> 模块。</p>
<p>如果我们需要打开一个 Excel 文件读入测试数据、再输出测试数据到这个 Excel 文件，我们需要使用 <a href="http://search.cpan.org/~jmcnamara/Spreadsheet-ParseExcel-0.54/lib/Spreadsheet/ParseExcel/SaveParser.pm">Spreadsheet::ParseExcel::SaveParser</a> 这个模块，它综合了 Spreadsheet::ParseExcel 和 Spreadsheet::WriteExcel 的功能。这里特别强调一下，不管是修改 (overwrite) 已有的 Excel 数据，还是创建 (add) 新的 Excel 数据，均可以使用 AddCell 这个方法，如下所示：</p>
<pre>
    <span># </span><span>Overwrite the string in cell A1
</span>    $worksheet-&gt;AddCell( $row, $col, <span>'New string'</span> );

    <span># </span><span>Add a new string in cell B1
</span>    $worksheet-&gt;AddCell( $row, $col + 1, <span>'Newer'</span> );
</pre>
<p> <strong>最重要的是，在用 AddCell 修改或是添加了新数据后，一定要记得保存 Excel 文件，否则修改不会被保存下来！</strong>保存文件用下面的语句：</p>
<pre>
    <span># </span><span>Write over the existing file or write a new file.
</span>    $template-&gt;SaveAs(<span>'newfile.xls'</span>);
</pre>
<p> 如果是同一个文件名，则把数据保存到原来的文件；如果是新文件名，则把数据保存到新的文件里。</li>
<li><a href="http://search.cpan.org/~abw/Badger-0.06/lib/Badger/Timestamp.pm">Badger::Timestamp</a>
<p>用 <a href="http://search.cpan.org/~abw/Badger-0.06/lib/Badger/Timestamp.pm">Badger::Timestamp</a> 模块可以很方便地对时间戳 (timestamp) 进行修改、比较等操作，相当方便。</p>
</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://blog.waterlin.org/articles/perl-modules-about-timestamp-excel-comments-cpp.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Perl 通过子过程的引用来调用子过程</title>
		<link>http://blog.waterlin.org/articles/reference-subroutines-by-user-input-in-perl.html</link>
		<comments>http://blog.waterlin.org/articles/reference-subroutines-by-user-input-in-perl.html#comments</comments>
		<pubDate>Mon, 21 Sep 2009 05:29:22 +0000</pubDate>
		<dc:creator>waterlin</dc:creator>
				<category><![CDATA[技术]]></category>
		<category><![CDATA[Perl]]></category>

		<guid isPermaLink="false">http://blog.waterlin.org/articles/reference-subroutines-by-user-input-in-perl.html</guid>
		<description><![CDATA[假如我有一个子过程，定义如下： sub test_sub { print "test"; } 我又有一个变量： $test = "test_sub"; 这个 $test 的值刚好就是上面子过程的名称。既然我通过 $test 知道了这个子过程名称，我可以通过 $test 达到调用这个子过程的目的吗？也就是说，我让用户从命令行里输入一个子过程的名称，然后就可以根据这个名称来调用相对应的子过程。 方法一，直接根据用户输入的子过程名来调用该子过程。 完整的例子代码如下： use warnings; no strict 'refs'; sub test_sub { print "test"; } $test = "test_sub"; $test-&#62;(); &#38;{$test}(); #anyway to invoke the subroutine 这里要注意，需要用 no strict 'refs'; 这个语句，否则脚本不能运行，Perl 解释器会提示类似于下面的错误： Global symbol &#8220;$test&#8221; requires explicit package name at [...]]]></description>
			<content:encoded><![CDATA[<p>假如我有一个子过程，定义如下：</p>
<pre>
<span>sub</span> <span>test_sub</span> {
    <span>print</span> <span>"test"</span>;
}
</pre>
<p>我又有一个变量：</p>
<pre>
$test = <span>"test_sub"</span>;
</pre>
<p>这个 $test 的值刚好就是上面子过程的名称。既然我通过 $test 知道了这个子过程名称，我可以通过 $test 达到调用这个子过程的目的吗？也就是说，我让用户从命令行里输入一个子过程的名称，然后就可以根据这个名称来调用相对应的子过程。</p>
<p>方法一，直接根据用户输入的子过程名来调用该子过程。</p>
<p>完整的例子代码如下：</p>
<pre>
<span>use</span> <span>warnings</span>;
<span>no</span> <span>strict</span> <span>'refs'</span>;

<span>sub</span> <span>test_sub</span> {
    <span>print</span> <span>"test"</span>;
}

$test = <span>"test_sub"</span>;

$test-&gt;();

&amp;{$test}();  <span>#</span><span>anyway to invoke the subroutine
</span>
</pre>
<p>这里要注意，需要用</p>
<pre>
<span>no</span> <span>strict</span> <span>'refs'</span>;
</pre>
<p>这个语句，否则脚本不能运行，Perl 解释器会提示类似于下面的错误：</p>
<p>Global symbol &#8220;$test&#8221; requires explicit package name at test2.pl line 10.</p>
<p>方法二，更常规的做法是专门用一个起分派作用的散列，根据用户输入的请示而调用相应的子过程。例如下面的 %dispatcher 就起到了绑定识别标记与相应子过程引用的作用，通过这个唯一的标记 (key)，我们可以很容易地找到对应的<a href="http://www.waterlin.org/wiki/PerlDereferencing.html">子过程引用</a>。</p>
<pre>
<span>my</span> <span>%dispatcher</span> = (
    <span>sub_test</span> =&gt; <span>sub</span> { <span>print</span> <span>"test"</span> },
);
</pre>
<p>然后可以用和方法一相同的语法来调用这个子过程：</p>
<pre>
<span>$dispatcher</span>{$sub_name}-&gt;();
</pre>
<p>下面是方法二的一个完整的例子：</p>
<pre>
<span>use</span> <span>warnings</span>;
<span>use</span> <span>strict</span>;

<span>sub</span> <span>test_sub</span> {
    <span>print</span> <span>"test\n"</span>;
}

<span>sub</span> <span>test_other</span> {
    <span>print</span> <span>"test other\n"</span>;
}

<span>my</span> <span>%dispatcher</span> = (
                  <span>"test_sub"</span>     =&gt; \&amp;test_sub,
                  <span>"test_other"</span>   =&gt; \&amp;test_other,
                 );

<span>print</span> <span>"\nPlease enter the test case you want to test:\n"</span>;

<span>while</span>( <span>my</span> <span>$cmd</span> = &lt;&gt; )
{
    <span>chomp</span>($cmd);

    <span>$dispatcher</span>{$cmd}-&gt;() <span>if</span> <span>exists</span> <span>$dispatcher</span>{$cmd};
}
</pre>
<p>当然，方法二要比方法一优秀得多，它可以避免用户输入错误的子过程名而导致一系列的麻烦。</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.waterlin.org/articles/reference-subroutines-by-user-input-in-perl.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Perl的两个小技巧</title>
		<link>http://blog.waterlin.org/articles/two-tricks-for-perl.html</link>
		<comments>http://blog.waterlin.org/articles/two-tricks-for-perl.html#comments</comments>
		<pubDate>Thu, 13 Aug 2009 06:02:46 +0000</pubDate>
		<dc:creator>waterlin</dc:creator>
				<category><![CDATA[技术]]></category>
		<category><![CDATA[Perl]]></category>

		<guid isPermaLink="false">http://blog.waterlin.org/articles/two-tricks-for-perl.html</guid>
		<description><![CDATA[今天碰巧用到，觉得挺有用的： 1) 用Perl获得当前目录的路径名： use Cwd; print getcwd; 2) 打印变量值到屏幕的同时，保存到一个变量里： print $str = &#8216;foo bar&#8217;; 当然，换成文件句柄也是一样的。]]></description>
			<content:encoded><![CDATA[<p>今天碰巧用到，觉得挺有用的：</p>
<p>1) 用Perl获得当前目录的路径名：</p>
<blockquote><p>use Cwd; <br />print getcwd;</p>
</blockquote>
<p>2) 打印变量值到屏幕的同时，保存到一个变量里：</p>
<blockquote><p>print $str = &#8216;foo bar&#8217;;</p>
</blockquote>
<p>当然，换成文件句柄也是一样的。</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.waterlin.org/articles/two-tricks-for-perl.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>在终端用Perl脚本自动补全输入内容</title>
		<link>http://blog.waterlin.org/articles/using-term-complete-module-in-perl-script.html</link>
		<comments>http://blog.waterlin.org/articles/using-term-complete-module-in-perl-script.html#comments</comments>
		<pubDate>Fri, 08 May 2009 08:48:38 +0000</pubDate>
		<dc:creator>waterlin</dc:creator>
				<category><![CDATA[技术]]></category>
		<category><![CDATA[Perl]]></category>

		<guid isPermaLink="false">http://blog.waterlin.org/articles/%e5%9c%a8%e7%bb%88%e7%ab%af%e7%94%a8perl%e8%84%9a%e6%9c%ac%e8%87%aa%e5%8a%a8%e8%a1%a5%e5%85%a8%e8%be%93%e5%85%a5%e5%86%85%e5%ae%b9.html</guid>
		<description><![CDATA[最近在用Perl来做工作的时候，运行到一个地方，需要我输入一个设备名，以判断接下来应该做的步骤。每次运行到这里，我都是手动输入很长的设备名，比如说ciscocontenteng，每次这样输入，不仅累死人，还很容易出错。 这种情况下，可以用Term::Complete这个module来实现用tab键自动补全。用法非常简单，看代码就差不多能理解了： use warnings; use strict; use Term::Complete; my @completion_list = (&#8220;atest&#8221;,&#8221;btest&#8221;,&#8221;cdtest&#8221;,&#8221;efgtest&#8221;); my $input = Complete(&#8216;please input the start character and use tab to complete: &#8216;, \@completion_list); #$input = Complete(&#8216;prompt_string&#8217;, @completion_list); print &#8220;The input word is: &#8220;.$input; 在上面的代码里，我们设定了一个数组@completion_list，里面包含了需要补全的名称，Perl就是根据这个列表来对你输入的字符进行补全的。Complete函数是主导这个工作的核心，它的第一个参数是在终端上输出提示输入的说明，第二个参数就是能用于补全的词组列表。 运行这个脚本的时候，你按tab键，Perl会自动用列表中的词来帮你补全，你输入回车确定补全、输入结束后，Perl会把你输入的内容存到变量$input里。 这样，以后就再也不用敲一长串的字符了。]]></description>
			<content:encoded><![CDATA[<p>最近在用Perl来做工作的时候，运行到一个地方，需要我输入一个设备名，以判断接下来应该做的步骤。每次运行到这里，我都是手动输入很长的设备名，比如说ciscocontenteng，每次这样输入，不仅累死人，还很容易出错。</p>
<p>这种情况下，可以用<a href="http://search.cpan.org/~nwclark/perl-5.8.9/lib/Term/Complete.pm" target="_blank">Term::Complete</a>这个module来实现用tab键自动补全。用法非常简单，看代码就差不多能理解了：</p>
<blockquote><p>use warnings; <br />use strict;</p>
<p>use Term::Complete;</p>
<p>my @completion_list = (&#8220;atest&#8221;,&#8221;btest&#8221;,&#8221;cdtest&#8221;,&#8221;efgtest&#8221;);</p>
<p>my $input = Complete(&#8216;please input the start character and use tab to complete: &#8216;, \@completion_list); <br />#$input = Complete(&#8216;prompt_string&#8217;, @completion_list);</p>
<p>print &#8220;The input word is: &#8220;.$input; </p>
</blockquote>
<p>在上面的代码里，我们设定了一个数组<strong>@completion_list</strong>，里面包含了需要补全的名称，Perl就是根据这个列表来对你输入的字符进行补全的。<strong>Complete</strong>函数是主导这个工作的核心，它的第一个参数是在终端上输出提示输入的说明，第二个参数就是能用于补全的词组列表。</p>
<p>运行这个脚本的时候，你按tab键，Perl会自动用列表中的词来帮你补全，你输入回车确定补全、输入结束后，Perl会把你输入的内容存到变量<strong>$input</strong>里。</p>
<p>这样，以后就再也不用敲一长串的字符了。</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.waterlin.org/articles/using-term-complete-module-in-perl-script.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>决定用Perl Pod定义自己的bug追踪系统</title>
		<link>http://blog.waterlin.org/articles/using-perl-pod-as-bug-tracking-system.html</link>
		<comments>http://blog.waterlin.org/articles/using-perl-pod-as-bug-tracking-system.html#comments</comments>
		<pubDate>Wed, 06 May 2009 06:27:51 +0000</pubDate>
		<dc:creator>waterlin</dc:creator>
				<category><![CDATA[技术]]></category>
		<category><![CDATA[Perl]]></category>

		<guid isPermaLink="false">http://blog.waterlin.org/articles/using-perl-pod-as-bug-tracking-system.html</guid>
		<description><![CDATA[最近，一直在苦苦寻找一个最适合自己的bug追踪系统。我自己平时写的一些小工具，有一些bug需要追踪管理一下，用记事本显得格式太随意了，不好管理。 试了很多有名的工具，如Bugzilla，Mantis，感觉都太厚重了，团队用倒是蛮合适的。 后来想着用XML定义一个日志数据库，一个Bug开一个文件，这样可以详细记录Bug的内容及解决过程、方法等。再写一个前端，用来管理组织这些XML文件。但我个人的bug量不多，更多的时候，是随手写一点想法，这种XML严谨的组织方式，并没有让我觉得更轻松。 尝试着用Emacs Muse记录了一段时间，有一个缺点，就是我写下来的解决方法里，有很多是代码，如果我不加&#60;verse&#62;&#60;/verse&#62;标签，Muse会尽量地帮我重新转义一下。总的来说，Muse还是偏排版多一点，不适合于记录随想随写的东西。 最后，我发现用Perl的pod来做自己的bug追踪系统挺好的。Pod虽然是个文档系统，但是只要灵活地运用标签也是能做简单的bug追踪系统。Pod的优点是，当你不需要用命令的时候，直接输入你的内容即可，总体来说，比较简洁。 我的pod格式定义如下： =pod =head1 project 1 =head2 Bug #000001 =head3 Bug #000001的简单描述或标题 Bug #000001的详细描述，所有的有关内容。。 =head3 Bug Status::Fixed =head3 Bug解决方法记录 =over indentlevel =item 解决步骤一 解决步骤一的内容。 =item 解决步骤二 解决步骤二的内容。 =item Bug Fix summary Solution of Bug #000001, the summary of this bug is: Try to readcord the document in time and in [...]]]></description>
			<content:encoded><![CDATA[<p>最近，一直在苦苦寻找一个最适合自己的bug追踪系统。我自己平时写的一些小工具，有一些bug需要追踪管理一下，用记事本显得格式太随意了，不好管理。</p>
<p>试了很多有名的工具，如Bugzilla，Mantis，感觉都太厚重了，团队用倒是蛮合适的。</p>
<p>后来想着用XML定义一个日志数据库，一个Bug开一个文件，这样可以详细记录Bug的内容及解决过程、方法等。再写一个前端，用来管理组织这些XML文件。但我个人的bug量不多，更多的时候，是随手写一点想法，这种XML严谨的组织方式，并没有让我觉得更轻松。</p>
<p>尝试着用Emacs Muse记录了一段时间，有一个缺点，就是我写下来的解决方法里，有很多是代码，如果我不加&lt;verse&gt;&lt;/verse&gt;标签，Muse会尽量地帮我重新转义一下。总的来说，Muse还是偏排版多一点，不适合于记录随想随写的东西。</p>
<p>最后，我发现用<a href="http://perldoc.perl.org/perlpod.html" target="_blank" title="PerlPod">Perl的pod</a>来做自己的bug追踪系统挺好的。Pod虽然是个文档系统，但是只要灵活地运用标签也是能做简单的bug追踪系统。Pod的优点是，当你不需要用命令的时候，直接输入你的内容即可，总体来说，比较简洁。</p>
<p>我的pod格式定义如下：</p>
<blockquote><p>=pod</p>
<p>=head1 project 1</p>
<p>=head2 Bug #000001</p>
<p>=head3 Bug #000001的简单描述或标题</p>
<p>Bug #000001的详细描述，所有的有关内容。。</p>
<p>=head3 Bug Status::Fixed</p>
<p>=head3 Bug解决方法记录</p>
<p>=over indentlevel</p>
<p>=item 解决步骤一</p>
<p>解决步骤一的内容。</p>
<p>=item 解决步骤二</p>
<p>解决步骤二的内容。</p>
<p>=item Bug Fix summary</p>
<p>Solution of Bug #000001, the summary of this bug is:</p>
<p>Try to readcord the document in time and in style.</p>
<p>这里就写一写把Bug搞定后的总结。</p>
<p>=back</p>
<p>=head2 Bug #000002</p>
<p>=head3 Bug #000002的简单描述或标题</p>
<p>Bug #000002的详细描述，所有的有关内容。。</p>
<p>=head3 Bug Status::Active</p>
<p>=head3 Bug解决方法记录</p>
<p>=over indentlevel</p>
<p>=item 解决步骤一</p>
<p>解决步骤一的内容。</p>
<p>=item 解决步骤二</p>
<p>解决步骤二的内容。</p>
<p>=item Bug Fix summary</p>
<p>Solution of Bug #000002, the summary of this bug is:</p>
<p>Try to readcord the document in time and in style.</p>
<p>这里就写一写把Bug搞定后的总结。</p>
<p>=back</p>
<p>=head2 Bug #000003</p>
<p>=head3 Bug #000003的简单描述或标题</p>
<p>Bug #000003的详细描述，所有的有关内容。。</p>
<p>=head3 Bug Status::Suspended</p>
<p>=head3 Bug解决方法记录</p>
<p>=over indentlevel</p>
<p>=item 解决步骤一</p>
<p>解决步骤一的内容。</p>
<p>=item 解决步骤二</p>
<p>解决步骤二的内容。</p>
<p>=item Bug Fix summary</p>
<p>Solution of Bug #000003, the summary of this bug is:</p>
<p>Try to readcord the document in time and in style.</p>
<p>这里就写一写把Bug搞定后的总结。</p>
<p>=back</p>
<p>=cut</p>
</blockquote>
<p>把上面的例子代码存成一个文档，比如说，我喜欢存为WaterBug.txt，后缀用.txt是为了方便用其它编辑器查看。</p>
<p>用pod2html的命令生成文档给其他人观看：</p>
<blockquote><p>pod2html &#8211;infile WaterBug.txt &#8211;outfile WaterBug.html &#8211;title WaterBug</p>
</blockquote>
<p>当然，你可以为这个文档写一个你自己的Style Sheet，生成一个打着你的logo的个性化文档：</p>
<blockquote><p>pod2html &#8211;infile WaterBug.txt &#8211;outfile WaterBug.html &#8211;title WaterBug &#8211;css stylesheet.css</p>
</blockquote>
<p>在定义我的pod格式时，我分别用<strong>Active</strong>，<strong>Suspended</strong>，<strong>Fixed</strong>，<strong>On-hold</strong>四种状态来标明Bug的状态，即&#8221;正在进行&#8221;、&#8221;还未开始&#8221;、&#8221;已经搞定&#8221;、&#8221;暂时放着&#8221;等四种状态，这些状态关键字都是以<strong>::</strong>开头进行标识。</p>
<p>以这些简单的标记来记录文档，我可以随手写在任何文本文件里，包括Google Docs这些在线文档，即使将来要转成其它格式的文档，也可以轻松地用perl来实现转换。</p>
<p>要查找特定状态的bug，只要搜索一下::Fixed或是::Suspended或是::Active或是::On-hold即可。</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.waterlin.org/articles/using-perl-pod-as-bug-tracking-system.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>用循环控制分步骤执行过长的Perl脚本</title>
		<link>http://blog.waterlin.org/articles/perl-slit-long-script-into-slides.html</link>
		<comments>http://blog.waterlin.org/articles/perl-slit-long-script-into-slides.html#comments</comments>
		<pubDate>Tue, 28 Apr 2009 08:37:25 +0000</pubDate>
		<dc:creator>waterlin</dc:creator>
				<category><![CDATA[技术]]></category>
		<category><![CDATA[Perl]]></category>

		<guid isPermaLink="false">http://blog.waterlin.org/articles/perl-slit-long-script-into-slides.html</guid>
		<description><![CDATA[最近在写一个比较长的Perl脚本，用来自动化实现做task的流程与步骤。但是，其中有一些很容易出错的步骤，比如说我的VPN没有开、某某服务没启动等，就执行不了一些操作，从而导致脚本运行出错。 这个时候，我只好先修复配置错误，然后重新从头执行脚本。这样浪费了大量的时间，也弄得我很烦躁。工作原本就没太多乐趣，而我，哪里可能记得住这么多琐碎的事呢？ 今天写了一个循环控制的东西，能在出错的步骤停止下来，等我修改了出错的步骤（系统环境而非代码本身），又能从中止的地方重新开始。示例代码如下： use warnings; use strict; sub test1 { print &#8220;test1\n&#8221;; } sub test2 { print &#8220;test2\n&#8221;; } sub test3 { print &#8220;test3\n&#8221;; } my $result = undef; sub controller { my $code_array = shift; my ($code,$code_name) = @$code_array; while (1) { my $new_result = eval {&#38;$code}; if ($@) { print &#8220;$@ \n Someting [...]]]></description>
			<content:encoded><![CDATA[<p>最近在写一个比较长的Perl脚本，用来自动化实现做task的流程与步骤。但是，其中有一些很容易出错的步骤，比如说我的VPN没有开、某某服务没启动等，就执行不了一些操作，从而导致脚本运行出错。</p>
<p>这个时候，我只好先修复配置错误，然后重新从头执行脚本。这样浪费了大量的时间，也弄得我很烦躁。工作原本就没太多乐趣，而我，哪里可能记得住这么多琐碎的事呢？</p>
<p>今天写了一个循环控制的东西，能在出错的步骤停止下来，等我修改了出错的步骤（系统环境而非代码本身），又能从中止的地方重新开始。示例代码如下：</p>
<blockquote><p>use warnings; <br />use strict;</p>
<p>sub test1 { <br />print &#8220;test1\n&#8221;; <br />}</p>
<p>sub test2 { <br />print &#8220;test2\n&#8221;; <br />}</p>
<p>sub test3 { <br />print &#8220;test3\n&#8221;; </p>
<p>}</p>
<p>my $result = undef;</p>
<p>sub controller { <br />my $code_array = shift; <br />my ($code,$code_name) = @$code_array; <br />while (1) { <br />my $new_result = eval {&amp;$code}; <br />if ($@) { <br />print &#8220;$@ \n Someting is wrong when execute $code_name, please input ENTER when you fix it.&#8221;; <br />&lt;&gt;; <br />} else { <br />last; <br />} <br />} <br />}</p>
<p>my @codes = ([\&amp;test1,"test1"],[\&amp;test2,"test2"],[\&amp;test3,"test3"]);</p>
<p>map {controller($_)} @codes; </p>
</blockquote>
<p>运行这段代码，会依次执行子函数test1，test2，test3等。</p>
<p>其中的eval语句，是必不可少的！有了eval后，如果子函数运行时出错或执行了die函数，就会返回一个undefined的值，并且错误消息也会存储到$@变量里；如果一切顺序，$@里就是一个空的字符串。有关这个用法，可以详细地看看<a href="http://perldoc.perl.org/functions/eval.html" target="_blank">perldoc里有关eval的说明</a>。</p>
<p>可以在test2或是其它子函数里插入一个die来试试中断的效果。</p>
<p>通过这样的结构，我就可以把很长的脚本分成若干个简短的子过程，大大地提高我的工作效率。另外要说明的是，代码本身的问题，并不能通过这样的方法来得到解决；还是得手动修改code，再重新运行。</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.waterlin.org/articles/perl-slit-long-script-into-slides.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>从Perl code里直接生成文档的方法</title>
		<link>http://blog.waterlin.org/articles/perl-using-pod-to-generate-doc.html</link>
		<comments>http://blog.waterlin.org/articles/perl-using-pod-to-generate-doc.html#comments</comments>
		<pubDate>Thu, 23 Apr 2009 08:23:53 +0000</pubDate>
		<dc:creator>waterlin</dc:creator>
				<category><![CDATA[技术]]></category>
		<category><![CDATA[Perl]]></category>

		<guid isPermaLink="false">http://blog.waterlin.org/articles/perl-using-pod-to-generate-doc.html</guid>
		<description><![CDATA[Perl支持把你的pod格式文字块生成文档，这个pod格式文字块可以是植入在代码里的标记语言，也可以是单独的一个文件。 有了pod，只要在写脚本的时候，随手记下想法、说明，就不用再另外编写文档了，非常方便。 建议先仔细读一读perldoc perlpod里面的内容，文档详细介绍了pod标记语言的语法。 $ perldoc perlpod 尽量保证一个比较好的书写习惯，例如： =pod =head1 NAME Water::Test &#8211; The great new Water::Test! =head1 VERSION Version 0.01 =cut 开始和结束都应该要空一行。当你用如上形式写到你的代码文件里后，你只要用pod2html, pod2man之类的命令，就可以把它转为文档。 例如，如果你把上面的代码保存为test.txt文件，则用如下命令可以把它转为html文档： $ pod2html &#8211;infile test.txt &#8211;outfile text.html]]></description>
			<content:encoded><![CDATA[<p>Perl支持把你的pod格式文字块生成文档，这个pod格式文字块可以是植入在代码里的标记语言，也可以是单独的一个文件。</p>
<p>有了pod，只要在写脚本的时候，随手记下想法、说明，就不用再另外编写文档了，非常方便。</p>
<p>建议先仔细读一读perldoc perlpod里面的内容，文档详细介绍了pod标记语言的语法。</p>
<blockquote><p>$ perldoc perlpod</p>
</blockquote>
<p>尽量保证一个比较好的书写习惯，例如：</p>
<blockquote><p>=pod</p>
<p>=head1 NAME</p>
<p>Water::Test &#8211; The great new Water::Test!</p>
<p>=head1 VERSION</p>
<p>Version 0.01</p>
<p>=cut</p>
</blockquote>
<p>开始和结束都应该要空一行。当你用如上形式写到你的代码文件里后，你只要用pod2html, pod2man之类的命令，就可以把它转为文档。</p>
<p>例如，如果你把上面的代码保存为test.txt文件，则用如下命令可以把它转为html文档：</p>
<blockquote><p>$ pod2html &#8211;infile test.txt &#8211;outfile text.html</p>
</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://blog.waterlin.org/articles/perl-using-pod-to-generate-doc.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

