2013-07-18 18 views
0

我试图让perltidy格式化的if声明是这样的:perltidy格式多线

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) 
    . ")"); 

to jum p到上一行像其他线路:

$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 

感谢。

回答

1

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

my $sth = $dbh->prepare('INSERT INTO image VALUES(NULL, ?, ?, ?, ?, ?)'); 
$sth->execute(
    $self->image, $self->extension, $self->location, 
    $self->modified, $self->accessed 
); 


我还发现格式跳跃:-fs到保护特定的代码段从perltidy。我在这里举了一个例子,但网站似乎做了一个斧头工作...