gpt4 book ai didi

perl - 说服 Perltidy 不理会空格

转载 作者:行者123 更新时间:2023-12-05 01:36:39 27 4
gpt4 key购买 nike

我正在使用 Perltidy将我的一些旧 Perl 文件重新格式化为更接近我当前偏好的样式。我遇到了这个片段的问题:

Fcntl::S_IRUSR & $mode

Perltidy 坚持删除 & 后面的空格 token ,导致:
Fcntl::S_IRUSR &$mode

……在我看来,这很碍眼。我该怎么做才能说服 Perltidy 离开那个单独的空间?我什至尝试了 -fws选项无济于事。

我正在使用 Perltidy 20101217,这显然是最新版本。

编辑:

一些额外的观察:
  • 使用 --indent-only ( -io ) 选项不会删除上述空间。
  • 以下等效代码段不受此问题的影响:
    $mode & Fcntl::S_IRUSR

  • 编辑2:

    我最终颠倒了 & 的顺序运算符参数,因为这似乎暂时解决了 Perltidy 问题。此外,这种方法不需要添加额外的括号或任何其他可能有助于 Perltidy 做正确事情的标记,但从长远来看肯定会让我感到困惑。

    更新:

    我就这个问题联系了 Perltidy 的作者 Steve Hancock。从他的回应来看:

    I checked and the problem is that the & is being mistokenized in this case as a function call sigil. The basic problem is that perltidy does not see prototypes for other modules, even built-in, so it has to guess when it comes to something like "Fcntl::S_IRUSR". In other words, it doesn't know if this is a function call or a constant, and has to guess. When you reversed the order it removed the ambiguity on the &.

    Thanks for the note. I'll see if I can come up with a patch to fix this.

    最佳答案

    它肯定错误地认为

    Fcntl::S_IRUSR & $mode

    方法
    Fcntl::S_IRUSR(&$mode)

    你可能可以通过使用来欺骗它
    (Fcntl::S_IRUSR) & $mode

    或者
    Fcntl::S_IRUSR() & $mode

    关于perl - 说服 Perltidy 不理会空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7973976/

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