First, because (1) contains a constant (the "1" part) and () contains no constants. So there are no constants being modified so why give an error complaining about you trying to modify no constants.

Second, as Perl is implemented, I detect a clear preference toward not disallowing things even if the implementor can't think of a good use for that thing at the time. This makes sense for a TIMTOWTDI language.

Third, we've just demonstrated a use for it. So it is a good thing it wasn't disallowed just because the use wasn't obvious at the time.

I suspect that this working was at least partially an accident. The list assignment code was written and tested and it worked. I doubt anyone tested this degenerate list assignment. In fact, searching the standard Perl test suite, I find that this feature is not tested but it is used when testing another feature:

# Should use magical autoinc only when both are strings print "not " unless 0 == (() = "0"..-1); print "ok 14\n"; for my $x ("0"..-1) { print "not "; } print "ok 15\n";
So there! q-:

        - tye (but my friends call me "Tye")

In reply to (tye)Re2: Getting the number of times a regexp matches by tye
in thread Getting the number of times a regexp matches by MeowChow

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.