gpt4 book ai didi

perltidy 格式复杂的 if

转载 作者:行者123 更新时间:2023-12-04 15:01:31 24 4
gpt4 key购买 nike

如何配置 perltidy 以格式化长 if 语句,如下所示:

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

或者像这样
if (
('this is an example' =~ /an.*example/ and 1 * 2 * 3 == 6)
or ('hello world' =~ /world/ and 6 == 3 * 2 * 1)
) {
print "hello\n";
}

编辑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

Edit2:想法是在第一个 ( 之后有一个新行还有最后一个 ){ 换行.如果这是不可能的,任何其他更好的格式建议将不胜感激。

最佳答案

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 "hello\n";
}

您可以控制花括号是否在新行上。您可以控制括号的松紧度。但是,您不能控制代码块中括号的新行。

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

关于perltidy 格式复杂的 if,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13394808/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com