0

我正在尝试perltidy格式化这样的if语句:

if ($self->image eq $_->[1]
        and $self->extension eq $_->[2]
        and $self->location  eq $_->[3]
        and $self->modified  eq $_->[4]
        and $self->accessed  eq $_->[5]) {

但无论我尝试什么,它都坚持这样格式化:

if (    $self->image eq $_->[1]
    and $self->extension eq $_->[2]
    and $self->location  eq $_->[3]
    and $self->modified  eq $_->[4]
    and $self->accessed  eq $_->[5]) {

另外,有没有办法得到这个块的最后一行:

$dbh->do("INSERT INTO image VALUES(NULL, "
    . $dbh->quote($self->image) . ", "
    . $dbh->quote($self->extension) . ", "
    . $dbh->quote($self->location) . ","
    . $dbh->quote($self->modified) . ","
    . $dbh->quote($self->accessed)
    . ")");

像其他行一样跳到上一行:

$dbh->do("INSERT INTO image VALUES(NULL, "
    . $dbh->quote($self->image) . ", "
    . $dbh->quote($self->extension) . ", "
    . $dbh->quote($self->location) . ","
    . $dbh->quote($self->modified) . ","
    . $dbh->quote($self->accessed) . ")");

这是我目前正在做的事情:

perltidy -ce -et=4 -l=100 -pt=2 -msc=1 -bar -ci=0 reporter.pm

谢谢。

4

1 回答 1

1

对于第一个问题,我没有什么可提供的,但是对于第二个问题,您是否考虑过重构它以使用占位符?它可能会更好地格式化,自动为您进行引用,并为您(和您的模块的用户)提供一个防止 SQL 注入问题的健康屏障。

我的 $sth = $dbh->prepare('INSERT INTO image VALUES(NULL, ?, ?, ?, ?, ?)');
$sth->执行(
    $self->image, $self->extension, $self->location,
    $self->修改,$self->访问
);


我还发现了 format skipping: -fs 来保护特定的代码段免受 perltidy 的影响。我会在这里举一个例子,但该站点似乎在它上面做了一个斧头工作......

于 2013-07-19T02:26:58.037 回答