Hi I have made one for the 4th day:)
=for advent_year 2011
=for advent_day 4
=for advent_title Getopt::Euclid
=for advent_author Joe Jiang
写脚本的时候,最麻烦的两件事,无非是写文档和设计用户接口。有了
Getopt::Euclid,这两件事情居然开始变得十分有趣了。应该说,文档驱>动的程序,这样的创意并不少见,可是用来作为用户接口,这真的还是让人觉得十分恰当。
相比其他的脚本参数分析模块,这个模块的知名度比较低,不过它的作者 Damian Conway 还是十分知名的。现在的维护者 Florent Angly
看起来
也是参数模块这方面的爱好者,一同被他收纳的还有 Getopt::Declare。
具体的使用方法可以参考以下的测试代码:
=begin code
#!/usr/bin/perl -wl
use Getopt::Euclid;
print for @{$ARGV{-i}};
=head1 NAME
demo-euclid - testing of module Getopt::Euclid
=head1 VERSION
This documentation refers to demo-euclid version 0.0.1
=head1 USAGE
demo-euclid [options] -i[n][file] <file>
=head1 REQUIRED ARGUMENTS
=over
=item -i[n][file] <file>
Specify input file
=for Euclid:
repeatable
file.type: readable
file.default: '-'
=back
=end code
有了以上的代码,你就可以这样测试一下了:
=begin code
$ perl demo-euclid.pl --version
This is demo-euclid.pl version 0.0.1
=end code
看上去还不错,这个工具脚本已经可以自动汇报版本号了!然后再测试一下正式的功能:
=begin code
$ perl demo-euclid.pl -i /etc/passwd -i /etc/group
/etc/passwd
/etc/group
=end code
这正是我们的工具需要的功能,也就是分行(因为 #! 行的末尾有个 l 选项)打印文件名。另外,文件不存在,或者不可读的时候,脚本还会自>动报错:
=begin code
$ perl demo-euclid.pl -i /etc/pass
Invalid "-i[n][file] <file>" argument.
<file> must be readable but the supplied value ("/etc/pass") isn't.
(Try: demo-euclid.pl --help)
$ perl demo-euclid.pl --help
Usage:
demo-euclid.pl -i <file>
...
=end code
看上去还挺专业的,连相应的帮助信息也有了。衷心希望你会喜欢上这个小模块!
2011/12/4 Michael Zeng <[email protected]>
> //comfort 重要的东西注意备份啊,
>
>
>
> 2011/12/4 cnhack TNT <[email protected]>
>
>> 准备生成 html 后再 commit 的。。。。
>>
>>
>> 2011/12/4 Fayland Lam <[email protected]>
>>
>>> 童鞋要注意经常 git commit or svn ci。
>>>
>>> Thanks
>>>
>>> 2011/12/4 cnhack TNT <[email protected]>
>>>
>>>> 原文是《使用 AnyEvent::HTTP 的高速代理验证程序》
>>>>
>>>> 55555....
>>>>
>>>>
>>>> 2011/12/4 cnhack TNT <[email protected]>
>>>>
>>>>> 欲哭无泪啊,写了一下午的 Day 4, 最后生成 html 的时候直接按 tab 做了这么个操作:
>>>>>
>>>>> cnhacktnt@Apollo:proxy$ pod2advent ae_proxy.pod > ae_proxy.pod
>>>>>
>>>>>
>>>>> 愣了一下,直接就悲剧了啊,还没 ci 到 git 里,
>>>>> 写的东西都没了。。。vim也退出了,连临时文件都没了。。。555,我敲了好几个小时啊。。。!
>>>>>
>>>>> 原文是《使用 AnyEvent::HTTP 的告诉代理验证程序》,现在只剩下代码了,算了,附上代码吧(见附件).
>>>>>
>>>>> 使用方式是,收集一部分待验证的 HTTP 代理地址,按如下格式存成 proxy.txt 文件:
>>>>>
>>>>>
>>>>> 201.75.96.153:3128
>>>>>
>>>>> 76.111.254.51:1111
>>>>>
>>>>> 211.139.10.183:80 <http://211.139.10.183/>
>>>>>
>>>>> 78.154.146.173:80 <http://78.154.146.173/>
>>>>>
>>>>> 200.52.133.188:8080
>>>>>
>>>>> 85.26.197.206:3128
>>>>>
>>>>> 86.110.154.82:3128
>>>>>
>>>>> 122.72.12.90:80 <http://122.72.12.90/>
>>>>>
>>>>> 203.114.146.116:3128
>>>>>
>>>>> 190.201.126.171:8080
>>>>>
>>>>> 202.108.5.114:80 <http://202.108.5.114/>
>>>>>
>>>>> 209.115.188.53:80 <http://209.115.188.53/>
>>>>>
>>>>> 90.182.144.34:3128
>>>>>
>>>>> 204.188.215.51:3128
>>>>>
>>>>> 69.247.158.186:1586
>>>>>
>>>>> 202.154.4.23:8080
>>>>>
>>>>> 190.5.199.18:3128
>>>>>
>>>>> 123.127.98.170:80 <http://123.127.98.170/>
>>>>>
>>>>> 109.75.64.30:3128
>>>>>
>>>>> 64.37.51.144:3128
>>>>>
>>>>> 然后使用如下命令:
>>>>>
>>>>> cat proxy.txt | perl ae_proxy.pl | tee ,result
>>>>>
>>>>>
>>>>> 就可以看到结果了,验证8000多个代理,耗时28秒。(如果待验证代理数量不足最大并发数,至少也要5秒,因为超时时间为5秒)
>>>>>
>>>>>
>>>>> 哭死!哭死!哭死!
>>>>>
>>>>> 血泪的教训,同学们打命令别太快了。。。。。
>>>>>
>>>>>
>>>> --
>>>> 您收到此邮件是因为您订阅了 Google 网上论坛的“PerlChina Mongers 讨论组”论坛。
>>>> 要向此网上论坛发帖,请发送电子邮件至 [email protected]。
>>>> 要取消订阅此网上论坛,请发送电子邮件至 [email protected]。
>>>> 若有更多问题,请通过 http://groups.google.com/group/perlchina?hl=zh-CN 访问此网上论坛。
>>>>
>>>
>>>
>>>
>>> --
>>> Fayland Lam // http://www.fayland.org/
>>>
>>> --
>>> 您收到此邮件是因为您订阅了 Google 网上论坛的“PerlChina Mongers 讨论组”论坛。
>>> 要向此网上论坛发帖,请发送电子邮件至 [email protected]。
>>> 要取消订阅此网上论坛,请发送电子邮件至 [email protected]。
>>> 若有更多问题,请通过 http://groups.google.com/group/perlchina?hl=zh-CN 访问此网上论坛。
>>>
>>
>> --
>> 您收到此邮件是因为您订阅了 Google 网上论坛的“PerlChina Mongers 讨论组”论坛。
>> 要向此网上论坛发帖,请发送电子邮件至 [email protected]。
>> 要取消订阅此网上论坛,请发送电子邮件至 [email protected]。
>> 若有更多问题,请通过 http://groups.google.com/group/perlchina?hl=zh-CN 访问此网上论坛。
>>
>
>
>
> --
> Yours Sincerely
> Zeng Hong
>
> --
> 您收到此邮件是因为您订阅了 Google 网上论坛的“PerlChina Mongers 讨论组”论坛。
> 要向此网上论坛发帖,请发送电子邮件至 [email protected]。
> 要取消订阅此网上论坛,请发送电子邮件至 [email protected]。
> 若有更多问题,请通过 http://groups.google.com/group/perlchina?hl=zh-CN 访问此网上论坛。
>
--
您收到此邮件是因为您订阅了 Google 网上论坛的“PerlChina Mongers 讨论组”论坛。
要向此网上论坛发帖,请发送电子邮件至 [email protected]。
要取消订阅此网上论坛,请发送电子邮件至 [email protected]。
若有更多问题,请通过 http://groups.google.com/group/perlchina?hl=zh-CN 访问此网上论坛。