in reply to Re^4: perltidy for ternary operator?
in thread perltidy for ternary operator?
Could one not just create a second ternary operation that perl would optimize out, such as the following?
print $coin ? q{heads} : 1 ? q{tails} : q{};
According to B:Deparse, the second ternary operator appears to be optimized out:
perl -MO=Deparse,-d \ -le \ 'my $coin = int(rand(2)); print $coin ? q{heads} : 1 ? q{tails} : q{};' BEGIN { $/ = "\n"; $\ = "\n"; } my $coin = int rand 2; print $coin ? "heads" : "tails"; -e syntax OK
However, the code, when handled by Perl::Tidy, appears to be formatted in the manner the OP is requesting:
perl -MPerl::Tidy -le ' my $code = q{my $coin = int(rand(2)); print $coin ? q{true} : 1 ? q{false} : q{};}; my $processed; Perl::Tidy::perltidy( source => \$code, destination => \$processed, argv => q{-npro -pbp -nst -se -bot -l=40}, ); print $processed;' my $coin = int( rand(2) ); print $coin ? q{true} : 1 ? q{false} : q{};
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.
|
---|
In Section
Seekers of Perl Wisdom