First Post in here

Giving this a try. I have been brought back into Perl world about a couple of years ago, by my old friend Luis Campos (LMC), and I am now writing some of my own modules in Modern (or quasi-) Perl.

Cheers!
Russian

This Wednesday - Tel Aviv.pm meeting!

This Wednesday (Dec. 29th) we'll have a TA.pm meeting of the Tel Aviv area (and anyone who wants to come visit!) at Shenkar College in Ramat Gan.

If you're interested in Perl (to learn, to improve, to steal cool stuff, to meet new interesting people), this meeting is for you!

PNG flyer.
PDF invitation.

ta_pm_291210.png

Why the Bovicidal Rage? (Killing Yacc: 4)

3299967437_6bae3ce6a8_z.jpg yacc was a major breakthrough. For the first time, automatic generation of of efficient, production-quality parsers was possible for languages of practical interest. Yacc-generated parsers had reasonable memory footprints. They ran in linear time.

But error reporting was overlooked. Then as now, the focus in analyzing algorithms was on power -- what kinds of grammar an algorithm can parse -- and on resource consumption. This leaves out something big.

Our frameworks for analyzing things affect what we believe. We find it hard to recognize a problem if our framework makes us unable to articulate it. Complaints about yacc tended to be kept to oneself. But while yacc's overt reputation flourished, programmers were undergoing an almost Pavlovian conditioning against it -- a conditioning through pain.

10分钟搭建一台Linux邮件服务器

我有一台Ubuntu Linux服务器,想快速开启邮件服务。例如,我的登录帐号是pyh,并且有一个域名example.com,那么如何把服务器配置成可收发pyh@example.com的邮件呢?在Ubuntu下,这些都很简单,几分钟就搞定。(注:我的是Ubuntu 9.10版本)

假如服务器的IP地址是12.34.56.78,首先配置域名,给该IP地址分配一个名字,例如mail.example.com。然后,将example.com域的MX记录设置为mail.example.com,注意MX不能直接指向IP地址。

然后在Ubuntu里,运行如下命令安装Postfix(不想sudo的话就用root安装):

apt-get install postfix

Postfix是一个MTA(邮件传输代理)。为什么用Postfix呢?因为一是它是Ubuntu的默认MTA,安装简单;二是它的配置文件大家都懂。

安装Postfix后,再安装sqwebmail,执行:

apt-get install courier-authdaemon
apt-get install sqwebmail

courier-authdaemon和sqwebmail都是Courier-MTA的标准组件。前者提供统一验证服务。后者是一套C写的webmail,简单快速,运行它后就可以通过网页来收发电子邮件。

执行上述几个apt-get后,MTA和webmail就都安装好并启动了,pstree看一下:

|-courierlogger---authdaemond---5*[authdaemond]
|-courierlogger---sqwebmaild
|-master-+-anvil
| |-pickup
| |-qmgr
| `-tlsmgr

第三行的master是Postfix的主进程。

安装完后就是配置,包括如下几个步骤:

(一)配置CGI

sqewebmail是通过CGI来运行的,要在web服务器里配置好它们。
系统里需要安装Apache。Apache是最广泛使用的支持CGI的web server,它的配置也大家都懂。

修改httpd.conf,加入如下内容:

  1. ScriptAlias /webmail/ "/usr/lib/courier/courier/webmail/"
  2. AllowOverride None
  3. Options None
  4. Order allow,deny
  5. Allow from all

第一行设置脚本目录别名,用户访问路径包含/webmail/,就定向到/usr/lib/courier/courier/webmail/,这是sqwebmail的可执行程序目录。第二行及后述行设置该目录可执行CGI。

然后,在Apache的文档目录(htdocs)里,设置一个符号链接:

ln -s /usr/share/sqwebmail .

将/usr/share/sqwebmail目录链接到Apache的文档根目录,这里放置sqwebmail的静态文件,如图片、CSS等。

设置完后,重启httpd。

(二)创建Maildir

切换到个人用户身份(如pyh),在家目录(/home/pyh)里,运行如下命令:

  1. maildirmake Maildir
  2. maildirmake -f Spam Maildir
  3. maildirmake -q 100000000S ./Maildir
  4. touch .courier
  5. sudo cp -r Maildir /etc/skel
  6. sudo cp .courier /etc/skel

Moved house - back on-line

Hi Folks

Well, I'm living with my mother, who has Alzheimer's, which is a bit like being out of work, in that I sit around a lot. But I can go out - I just have to lock the front door and garden gate so she doesn't accidently let my 2 miniature dogs out.

Nevertheless, I hope to be still productive in the Perl arena.

So, post frequently, and that'll give me things to read :-).

Obfuscation: Comparing the size of two arrays

~~@x ~~ ~~@y

is true if @x and @y have the same number of elements.

This rather elegant obfuscation uses the smart match operator as well as double bitwise negation.

RTF::Parser is looking for a new home

Absolutely ages ago, I took over maintainership of RTF::Parser. Grand plans abounded, but mostly what I ended up doing was fixing a few of the more outrageous bugs, and made it use the much more sensible RTF::Tokenizer as its back end.

People still use RTF::Parser, and a couple of other modules on CPAN use it, but I really can't give it the love and care it deserves. The code is mildly crazy, there are age-old outstanding bugs on rt ... this Xmas, will you take in a deserving module?

-P

一些电子邮件反垃圾方法

RBL:IP黑名单、URL黑名单,常用的有Spamhaus、Spamcop、Sorbs、NJABL等。
SPF:检查发送者IP是否在发送域的授权IP范围内。
频率控制:限制发送频率。
信誉系统(reputation):对sender的IP或domain建立信誉评分机制。
DomainKey:采用数字签名对发送域进行验证。
灰名单(greylist):对可疑邮件返回450,临时拒绝对方一段时间。
指纹(fingerprint):对垃圾邮件建立指纹样本库。
蜜罐(honeypot):设立蜜罐邮箱,用来采集垃圾邮件样本。
贝叶斯(Bayes):对邮件内容进行分词和基于Bayes算法的统计。
关键字:内容关键字过滤。
渐进式规则评分系统(启发式过滤):SpamAssassin。
基于上下文的系统:对邮件内容、邮件组织方式、发送者信誉进行综合统计,如IronPot。
基于行为分析的系统:从全球地理位置角度统计垃圾邮件行为和特征,如CommTouch。

通常是各个技术措施综合起来对垃圾邮件进行识别和过滤。例如基于规则的反垃圾方法,可以准确的识别已知垃圾邮件,但对于新出现的垃圾邮件则无能为力。而基于统计的方法(如Bayes),则可以较准确的预防新垃圾邮件。还有基于内容的方法(如关键字)与基于行为的方法结合起来,才能发挥更好的效果。

Expanding Your Author Info in the MetaCPAN

If you've had a look at search.metacpan.org, you may have noticed that some of the author pages have more info than you might find at search.cpan.org. Take, for instance, FREW's author page. You'll see that it has links to his blog, Twitter, StackOverflow, website etc. Lots of information there which allows you to find his various online presences without having to do all too much digging around.

If you'd like to expand your author info, it's pretty easy. We don't have a login for you yet, but this is a trivially easy stop-gap solution to get yourself up and running:

  • Fork the CPAN-API project on Github
  • Have a look at conf/author.json to get an idea of which fields you may want to add
  • Create an author.json file and save it to your author folder (eg conf/authors/O/OA/OALDERS/author.json)
  • Commit your changes and send a pull request

vim: add a 'use' statement without moving the cursor

You're writing Perl code in vim and have just typed a package name - maybe you want to create an object of this class:

some_statement;
my $o = Some::Class->new;
do_something_with($o);

You obviously need to write use Some::Class at the top. So you either move the cursor near the top and add the line, then jump to the previous line number, or maybe you split the window, move to the new viewport, make the change, then close that viewport.

test post

hi there, this is a test

为什么我不喜欢SPF

SPF即Sender Policy Framework(发送者策略框架),用来防止垃圾电子邮件。简言之,发送方在自己域名(例如163.com)的DNS TXT记录里,标明一些IP地址段,这些地址段包括了发送方的合法IP地址。接收方MTA在收到这个域的邮件时,可选择的查询SPF记录(TXT)。如果发送者IP地址不在SPF里,则采取相应策略,例如拒收或丢弃邮件。

SPF在一定程度上有用,但是它有很多麻烦,我个人对SPF持保留意见。如果反垃圾过度依赖SPF,会造成一些问题。包括:

一. 邮件转发问题

例如,163发给263,263转发给新浪。263在转发的SMTP会话里,可能使用mail from:这种形式。如果Sina严格检查163的SPF,会认为263是欺诈行为,从而拒收这封转发邮件。

二. SMTP Relay问题

国外大多数ISP,例如Comcast、Earthlink、Arcor等,都对订阅用户提供SMTP Relay服务。例如我有一个德国Arcor帐号,可以使用它的邮件服务器,在通过认证后发送任何域(包括163.com)的电子邮件。如果接收方MTA检查SPF,那么设置了严格SPF的域的邮件就发不过去。

三. Yahoo webmail问题

Yahoo的webmail里可以设置发送任何外域(例如163.com)的邮件。并且Yahoo服务器在发送这些邮件时,跟Gmail、Live不同,它在SMTP会话里使用了真正的mail from:这种形式。因此,设置了严格SPF的域的邮件,通过Yahoo就基本发不出去。

因为如上等原因,国外一些大的邮件提供商如Yahoo,没有设置SPF记录。Hotmail、Gmail、Comcast等,将SPF设置为很宽松的?all或者较宽松的~all。而国内大型的邮件提供商网易、新浪,SPF设置为最严格的-all,毫无退路,并不可取。QQ、Sohu等SPF 为~all,要明智一些。

perl5.10, give back our $_

perl5.10 added given keyword. very nice.

However, given("foo") does my $_ = "foo"(lexical $_) implicitly. This means it does not work code using local $_ in given block. like this:

One-liner to count the number of lines in a file

There is a cute Perl one-liner to count the number of lines in a file:

perl -nE'}{say$.' foo.txt

Let's see how perl parses this one-liner:

mention of Perl in a fun story

Especially I like last line. Wikileaks To Leak 5000 Open Source Java Projects With All That Private/Final Bullshit Removed.

P.S. Stevey's Tech News, Issue #1 is also fun.

Morpheus - ultimate configuration engine

As I promised, here are the slides from my talk this morning at Saint Perl-2 in Saint-Petersburg, Russia.

I believe Morpheus can be very useful for the community and hope that it'll become widely adopted.
There are still a lot of things which can be added, but conceptually we are on the right track.

These slides probably suck (I wrote them in the last moment and didn't put enough details in some places), but putting code out in the wild and getting feedback is more important by now.

One more thing, if you're going to check out PODs in next few days, see them on github instead of CPAN. There are much more of them added in 0.36 release, which is not uploaded to CPAN yet.

UPD: Just found out that 0.36 release docs can be viewed here: http://search.cpan.org/~mmcleric/Morpheus-0.36/
Morpheus::Key, Morpheus::Bootstrap and Morpheus::Plugin::Content PODs are worth to be looking at, if you are interested in implementation detals.

Backlogging...

It has been quite a while since I last wrote. I think this is how 50% of blog entries around the world begin.

I've amassed a bit of a backlog over the last few weeks, and blogging was a part of it. This is the rest of the backlog.

Scalar context gotchas

On Twitter, Curtis Poe (@OvidPerl) posted some interesting and unintuitive Perl code; I've slightly reformatted it and changed some values for the sake of the following discussion.

use Data::Dumper;
sub boo { 4,5,6 }
my @x = ( boo() || 5,8,7);
print Dumper \@x;

What do you think this prints?

Let's look at some simpler examples of code:

$ perl -le'@x = (4,5,6,7,8); $y = @x; print $y'
5

An array like @x, in scalar context, evaluates to the number of elements in that array. In this case, @x contains five elements.

$ perl -le'$y = (4,5,6,7,8); print $y'
8

Any::URI::Escape percent encoding issues

In case you haven't seen it yet, Mark Stosberg posted an excellent analysis of percent encoding issues in several CPAN modules, including Any::URI::Escape, a module I whipped up one weekend - http://mark.stosberg.com/blog/2010/11/percent-encoding-uris-in-perl.html

Grantreport - Perl 6 Tablets - 5th week // Perl 5 Testing

By week i mean 7 days in which I touched the tablets.

Basically i just read the advent calendar and other sources and check if the tablets missing something. This way Appendix A has 25 entries more, much more revamped finding even keyword fossils of ancient Perl 6, not even known to moritz++, jnthn++ was helpful too. Also wrote the section about quoting and some minor parts of tablet 3.

Other than then I wrote last week an article for the next (10th) Perlzeitung about basics in Perl testung, because even beginners can't start too early with that. Since Perl's official Testing site lies pretty dormant I maybe take the brush to sweep there some things. but hej bigmouth I dont even got time follow properly p5doc and still in the starts for my thingy for the perl ecosystem group (still a seakrit). But my anger toward that subject rises. Any other volunteers for that out there?

About blogs.perl.org

blogs.perl.org is a common blogging platform for the Perl community. Written in Perl with a graphic design donated by Six Apart, Ltd.