Can 'use strict' warn instead of error

前端 未结 5 1198
没有蜡笔的小新
没有蜡笔的小新 2021-01-19 04:31

When using use strict perl will generate a runtime error on unsafe constructs. Now I am wondering if it is possible to have it only print a warning instead of c

5条回答
  •  时光取名叫无心
    2021-01-19 04:44

    The warnings and strict pragmas are complementary, not overlapping. The strict pragma has both compile-time and run-time effects. You can't reduce the severity of strictures from errors to warnings, but you can disable them entirely. For example, if you're writing your own export routine you'll need to enable symbolic references in order to manipulate the symbol table.

    {
        no strict 'refs';
        # symrefs okay within this block
    }
    

    Warnings can also be disabled lexically (assuming you did use warnings instead of the largely obsolete -w flag).

    Strictures and warnings provide a safety net. That's why they're recommended to be used by default. If you disable them you should disable only what's necessary and limit the change to the smallest possible scope.

提交回复
热议问题