Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Weird? regex Question

by HyperZonk (Friar)
on Jul 25, 2001 at 04:22 UTC ( [id://99528]=note: print w/replies, xml ) Need Help??


in reply to Weird? regex Question

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://99528]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (6)
As of 2024-04-23 14:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found