Why are Perl source filters bad and when is it OK to use them?

后端 未结 7 1524
Happy的楠姐
Happy的楠姐 2020-11-30 07:55

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

7条回答
  •  感动是毒
    2020-11-30 08:21

    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.

    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.

    See also: Perl Cannot Be Parsed: A Formal Proof

提交回复
热议问题