String increment should fail loudly when the conditions for it are not met.

Given how "++" is, in a sense, intrinsically overloaded, and given Perl's intrinsic flexibility about interpreting the "data type" (string? int? float?) of a scalar value, I would be hesitant to ask for whole lot of special condition checks on this operator, for fear of slowing down all the scripts that use it so often. There's only a limited amount of idiot-proofing that the language can do for you and still be deemed suitable for effective use.

Even when strings do "meet the conditions", it's still no guarantee that you're going to end up with what you intended:

$ perl -le '$x="12345678901234567890"; print $x; ++$x; print $x' 12345678901234567890 12345678901234567891 $ perl -e '$x="12345678901234567890";printf "%20.0f\n",$x; ++$x;printf + "%20.0f\n",$x' 12345678901234567168 12345678901234567168 # or, just as bad: $ perl -le '$x="12345678901234567890"; printf "%20.0f\n",$x; ++$x; pri +nt $x' 12345678901234567168 1.23456789012346e+19
I agree with the view expressed below: the current behavior is consistent, in a way that makes sense, with other related behaviors. (++Fletch ! ... or should I say "Fletci !") (updated for grammar correction)

In reply to Re^2: String increment - reasoning by graff
in thread String increment - reasoning by throop

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.