加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

perltidy格式复杂如果

发布时间:2020-12-15 22:06:44 所属栏目:大数据 来源:网络整理
导读:如何将perltidy配置为格式化if if语句如下: if ( ('this is an example' =~ /an.*example/ and 1 * 2 * 3 == 6) or ('hello world' =~ /world/ and 6 = 3 * 2 * 1)) { print "hellon";} 或者像这样 if ( ('this is an example' =~ /an.*example/ and 1 * 2
如何将perltidy配置为格式化if if语句如下:
if (
    ('this is an example' =~ /an.*example/ and 1 * 2 * 3 == 6) or
    ('hello world' =~ /world/ and 6 = 3 * 2 * 1)
) {
    print "hellon";
}

或者像这样

if (
    ('this is an example' =~ /an.*example/ and 1 * 2 * 3 == 6)
    or ('hello world' =~ /world/ and 6 == 3 * 2 * 1)
) {
    print "hellon";
}

编辑1:perltidyrc

--maximum-line-length=100
--indent-columns=4
--default-tabsize=4
--continuation-indentation=4
--closing-token-indentation=0

--no-indent-closing-brace

--paren-tightness=2
--square-bracket-tightness=2
--block-brace-tightness=0

--trim-qw

--nospace-terminal-semicolon
--nospace-for-semicolon

--indent-spaced-block-comments
--ignore-side-comment-lengths

--cuddled-else

--no-opening-brace-on-new-line
--no-opening-sub-brace-on-new-line
--no-opening-anonymous-sub-brace-on-new-line
--no-brace-left-and-indent

--blanks-before-comments
--blank-lines-before-subs=1
--blanks-before-blocks
--maximum-consecutive-blank-lines=1

编辑2:我们的想法是在第一个(也是最后一个)后面有一个换行符号{.如果这是不可能的,任何其他建议更好的格式将不胜感激.

解决方法

perltidy的默认样式是尽可能遵循 Perl Style Guide.这导致了这个输出:
if (   ( 'this is an example' =~ /an.*example/ and 1 * 2 * 3 == 6 )
    or ( 'hello world' =~ /world/ and 6 == 3 * 2 * 1 ) )
{
    print "hellon";
}

您可以控制花括号,无论它们是否在新行上.您可以控制括号的紧密度.但是,您无法控制代码块中括号的新行.

默认样式尽可能接近您想要的输出.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读