in reply to Re: Re: Getting the number of times a regexp matches
in thread Getting the number of times a regexp matches
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:
So there! q-: - tye (but my friends call me "Tye")# 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";
|
|---|