为什么Perl源过滤器不好,何时可以使用它们? [英] Why are Perl source filters bad and when is it OK to use them?

查看:105
本文介绍了为什么Perl源过滤器不好,何时可以使用它们?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

常识"是源过滤器是错误的,不应在生产代码.

It is "common knowledge" that source filters are bad and should not be used in production code.

回答相似时,但有更具体的问题,我找不到任何能很好地说明过滤器质量不好的原因以及何时可以安全使用过滤器的良好参考.我认为现在是时候创建一个了.

When answering a a similar, but more specific question I couldn't find any good references that explain clearly why filters are bad and when they can be safely used. I think now is time to create one.

  1. 为什么源过滤器不好?
  2. 什么时候可以使用源过滤器?

推荐答案

只有perl可以解析Perl(请参见

Only perl can parse Perl (see this example):

@result = (dothis $foo, $bar);

# Which of the following is it equivalent to?
@result = (dothis($foo), $bar);
@result = dothis($foo, $bar);

这种模棱两可的特性使得很难编写总是成功并且做正确的事情的源过滤器.当出现问题时,调试会很麻烦.

This kind of ambiguity makes it very hard to write source filters that always succeed and do the right thing. When things go wrong, debugging is awkward.

几次崩溃和刻录后,我开发了一种迷信方法,从不尝试编写其他源过滤器.

After crashing and burning a few times, I have developed the superstitious approach of never trying to write another source filter.

不过,我偶尔会使用 Smart :: Comments 进行调试.完成后,我会在命令行上加载模块:

I do occasionally use Smart::Comments for debugging, though. When I do, I load the module on the command line:

$ perl -MSmart::Comments test.pl

以避免任何可能在生产代码中保持启用状态的机会.

so as to avoid any chance that it might remain enabled in production code.

另请参见: 无法解析Perl:形式证明

这篇关于为什么Perl源过滤器不好,何时可以使用它们?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆