G'day perl-diddler,

To be honest, I got the impression that you made a coding error

$ perl -MO=Deparse,-p -e 'my $str = " " x $col%$maxcol;' (my $str = ((' ' x $col) % $maxcol)); -e syntax OK

and instead of simply fixing it with the addition of a pair of parentheses

$ perl -MO=Deparse,-p -e 'my $str = " " x ($col%$maxcol);' (my $str = (' ' x ($col % $maxcol))); -e syntax OK

you decided that Perl should change to accomodate you.

If you simply want a maximum amount of indentation, your logic (regardless of syntax) is wrong. When you see your output starting to zigzag across the screen, will you change your code to

$ perl -MO=Deparse,-p -e 'my $str = " " x $col > $maxcol ? $maxcol : $ +col;' (my $str = (((' ' x $col) > $maxcol) ? $maxcol : $col)); -e syntax OK

instead of

$ perl -MO=Deparse,-p -e 'my $str = " " x ($col > $maxcol ? $maxcol : +$col);' (my $str = (' ' x (($col > $maxcol) ? $maxcol : $col))); -e syntax OK

and then want the precedence of the ternary operator to change as well.

Now, let's say your indentation was based on tabs of four spaces and your check also needed to take a margin into consideration. This code would no longer work as expected under your new precedence rules:

$ perl -MO=Deparse,-p -e 'length " " x $expr + $margin' length(((' ' x $expr) + $margin)); -e syntax OK
"The 'x' operator isn't commutative"

So what? The '/' and '%' operators aren't commutative either: do you want to change their precedence as well based on commutativity?

"So it would only change in P20 or P22 if it were to change, ..."

By that, I assume you mean version 5.20 or 5.22. The 'x' operator has been around, with the same precedence, since at least Perl 4 (it's in my first edition Programming perl) — so, that's at least 22 years (see perlhist) of code that could potentially just break for anyone upgrading perl.

"To me, it looks like a prime situation for perl's precedence rules to change in a mostly backwards compatible way ..."

There is nothing in your post that suggests backwards compatibility. Perhaps you also want:

use feature 'diddler_precedence';

In closing, I see no merit whatsoever in what you're proposing. Just add the parentheses to your broken code and move on with your life.

-- Ken


In reply to Re: Precedence design question...'x' & arith by kcott
in thread Precedence design question...'x' & arith by perl-diddler

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.