http://qs321.pair.com?node_id=1109424


in reply to perltidy for ternary operator?

I looked into PBP and that's not what it says!

It recommends to

Format cascaded ternary operators in columns
and that's exactly what the -pbp switch does:

lanx@lanx-1005HA:~$ cat /tmp/tst.pl my $var1 = $condition ? $val_for_true : $val_for_none ; my $var2 = $condition ? $val_for_true : $condition2 ? $val_for_ +true2 : $val_for_none ; lanx@lanx-1005HA:~$ perltidy -pbp /tmp/tst.pl my $var1 = $condition ? $val_for_true : $val_for_none; my $var2 = $condition ? $val_for_true : $condition2 ? $val_for_true2 : $val_for_none;

I'd appreciate if you'd fix the typo in the title, provide links to documentation of the modules (like perltidy) and chapters (like "Ternaries") you are questioning.

Cheers Rolf

(addicted to the Perl Programming Language and ☆☆☆☆ :)

Replies are listed 'Best First'.
Re^2: perltidy for ternary operator?
by TomDLux (Vicar) on Dec 06, 2014 at 18:54 UTC

    Page 32 of PBP, first edition : </p

    You can use the tabular layout even if you have only a singular ternary .... Starting out this way makes it easier for maintainers to subsequently add new alternatives to the table.
    

    As Occam said: Entia non sunt multiplicanda praeter necessitatem.

      That's a suggestion ("you can") for the case you expect new entries to come.

      But that's not a problem with perltidy, cause cascades (as demonstrated) would be fixed automatically.

      And I doubt that breaking simple ternaries would be appreciated by the majority.

      It might interest you that tidy's output of a simple ternaries depends on existing linebreaks: (see -bot option)

      lanx@lanx-1005HA:~$ cat /tmp/tst.pl my $var1 = $condition ? $val_for_true : $val_for_none ; #own linebreak my $var2 = $condition ? $val_for_true : $val_for_none ; lanx@lanx-1005HA:~$ perltidy -pbp /tmp/tst.pl my $var1 = $condition ? $val_for_true : $val_for_none; #own linebreak my $var2 = $condition ? $val_for_true : $val_for_none;

      Since the documentation mentions ternaries only once for -bot I doubt your goal can be achieved! (i.e. without patching the code)

      Cheers Rolf

      (addicted to the Perl Programming Language and ☆☆☆☆ :)

      update

      ) i.a.W if you expect the ternary to be cascaded in the future then enter a linebreak manually.

        I didn't ask how to achieve what the majority want, I asked how to achieve what I want.

        As Occam said: Entia non sunt multiplicanda praeter necessitatem.