woei has asked for the wisdom of the Perl Monks concerning the following question:

Hi fellow monks,

I'm trying to find a perltidy option that exhibits the following behaviour, consider:<P

use Carp qw(confess); use Cwd qw(abs_path); use File::Basename qw(fileparse); use Data::Dumper qw(); use Digest::SHA1 qw();

Is there a perltidy option that'd format it as:

use Carp qw(confess); use Cwd qw(abs_path); use File::Basename qw(fileparse); use Data::Dumper qw(); use Digest::SHA1 qw();

I remember having seen it before, but reading through the man page fails to come up with anything. Thanks!

Replies are listed 'Best First'.
Re: Help trying to find a Perltidy option
by Anonymous Monk on Jun 11, 2010 at 10:31 UTC
    I remember having seen it before, but reading through the man page fails to come up with anything.

    perldoc perltidy |grep -i qw Trimming whitespace around "qw" quotes -tqw or --trim-qw provide the default behavior of trimming space +s around multi-line "qw" quotes and indenting them appropriately. -ntqw or --notrim-qw cause leading and trailing whitespace aroun +d multi-line "qw" quotes to be left unchanged. This option will no +t in some versions of perl, trimming "qw" quotes changes the synta +x ssc st sts syn t tac tbc toc tp tqw tsc w x bar k +is Perltidy indents but does not reformat comments and "qw" quotes.
    The documentation says it only indents for multi-line qw, so there is no perltidy option for what you want
      Here is a workaround, first use this one-liner to indent your use lines
      perl -pe " s/^use\s+(\S+)\s+(.+)$/sprintf q!use %-20s %s!, $1, $2/e; " + < input > output
      then tell perltidy ignore that section by surrounding it with #<<< and #>>> and you get
      #<<< do not let perltidy touch this use Carp qw(confess); use Cwd qw(abs_path); use File::Basename qw(fileparse); use Data::Dumper qw(); use Digest::SHA1 qw(); #>>>
      Do either "-wls=q" or "-wls=Q" work? They should insert white space before any qw block (first form) or any quote/pattern (second form). The only side effect is that it would be everwhere, not just after USE statements.

      edit: they don't work for this :-(