Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: [OT] Thoughts on Ruby's new absent operator?

by Eily (Monsignor)
on Mar 24, 2017 at 13:22 UTC ( [id://1185779]=note: print w/replies, xml ) Need Help??


in reply to [OT] Thoughts on Ruby's new absent operator?

Although it's fairly simple to translate the operator into perl, I don't see a way that does not involve repeating the contained expression: /A(?~BCD)E/ would match the same thing as /A(?: (?!BCD).* | (?:BCD).+ )E/x (ie: BCD is allowed to match between A and E if the string is not strictly BCD)

This looks like an easy way to exclude some values from a match precisely and explicitly. One example I can think of is if you have emails with the pattern firstnamesurname@company.pl and want to match last names in @lastnames, but not first names in @firstnames, you could do:
$" = |; /^(?~@firstnames)(?:@lastnames)[@]company[.]pl/;
without having to care if one of the matching names starts like one of the ignored ones (eg: benjamin and ben). I don't see how you'd end up searching for something like that though :P

Edit: even (?: (?!REGEX).* | (?:REGEX).+ ) can't be expected to always give the same result as (?~REGEX).
Eg: ABC =~ /A(?~BC)BC/ would be true (because the empty string is not BC), but ABC =~ /A(?: (?!BC).* | (?:BC).+ ) )BC/x; would be false because both branches fail. (?: (?!REGEX).+ | (?:REGEX).+ )? would work I think.

Edit2: even the latter would not be correct with (?~REGEX|) (ie, if the empty string is not allowed). So there actually is no way to turn (?~REGEX) into a perl equivalent without understanding what REGEX matches (Edit: well, I can't think of one right now at least).

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2024-03-28 18:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found