Update: And to think, I actually even tested
the code! As
ChemBoy said yesterday (I must not have been
listening), "Test both cases before speaking." Fortunately,
someone pointed out the error of my ways. The
answer given below is entirely wrong ... at least, the
substitution part of it, it would seem. Here's me saying
"I really haven't figured it out yet." If I do before someone
else gets in, I'll post my results here for everyone to see,
along with my shame, below.
RIGHT ANSWER:
Heh heh <blush> and it was so easy, too ...
In an RE, | refers to alternate matches. Strangely, you can
capture the zero-width assertion end-of-line or a '--' at the
end of the line just as shown. This RE finds the arbitrary
characters followed by a space or a space-dash-dash at the
end of the line; either case is a match, and either the null
string or the dash-dash is captured in $1.
WRONG ANSWER:
I will admit right up front that the RE looks very strange to
me, also ... perhaps japhy or a similar REMaster can sort
out exactly what this is supposed to do. However, $ is only
a "positional anchor" when used as the last
character in the regex. Otherwise, it indicates variable
substitution in the normal double-quote method. Thus, the
first thing the parentheses capture is the character matching
whatever $| is set to ($| is the autoflush flag, BTW), followed
by two dashes at the end of the line. On my system, $| is
normally set to '' (empty string), but it could be set to 1
if autoflush has been enabled using the typical Perl idiom
$|++;. Again, I have no idea why you might want
to do such a thing, except as an Obfu, of course!
-
HZ