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

I'd like my lists to have one item per line, unless they are two items split by the arrow operator, but haven't figured out how to make perltidy do this. Any suggestions?

Here's an example:

my @list = ('1', '2', '3', ); my %hash = (a => '1', b => '2', c => '3', );

Replies are listed 'Best First'.
Re: perltidy list formatting
by Util (Priest) on Oct 26, 2005 at 20:41 UTC

    By default, perltidy handles list with fat commas differently than plain lists. See "Controlling List Formatting" in the perltidy man page. This worked for me:

    perltidy -st -cab=1 -mft=1 -lp -vt=1 -boc PM_503139_02.pl
    Output:
    my @list = ( '1', '2', '3', ); my %hash = ( a => '1', b => '2', c => '3', );
    Key:
    -boc --break-at-old-comma-breakpoints -mft=n --maximum-fields-per-table=n -cab=n --comma-arrow-breakpoints=n -lp --line-up-parentheses -pt=n --paren-tightness=n -vt=n --vertical-tightness=n -vtc=n --vertical-tightness-closing=n
    The real problem was in stopping @list from being flattened into one line, which perlytidy wants to do whenever the list *could* fit on a single line. The '-boc' flag, which tells it to using existing linebreaks, keeps @list in multi-line form, but this may be non-optimal for formatting the rest of your program.

      Thanks, -boc looks like what I need.
Re: perltidy list formatting
by planetscape (Chancellor) on Oct 27, 2005 at 06:51 UTC