Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^2: perltidy for ternary operator?

by TomDLux (Vicar)
on Dec 06, 2014 at 18:54 UTC ( [id://1109427]=note: print w/replies, xml ) Need Help??


in reply to Re: perltidy for ternary operator?
in thread perltidy for ternary operator?

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.

Replies are listed 'Best First'.
Re^3: perltidy for ternary operator?
by LanX (Saint) on Dec 06, 2014 at 19:06 UTC
    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.

        Could one not just create a second ternary operation that perl would optimize out, such as the following?

        According to B:Deparse, the second ternary operator appears to be optimized out:

        However, the code, when handled by Perl::Tidy, appears to be formatted in the manner the OP is requesting:

        I know that may not be what the OP was hoping for, but perhaps it might be an option to look at.

        Hope that helps.

        And you got an answer: patch the code.

        There is no option for your private needs

        Cheers Rolf

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1109427]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (2)
As of 2025-07-19 23:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.