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?? |
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: Edit: even (?: (?!REGEX).* | (?:REGEX).+ ) can't be expected to always give the same result as (?~REGEX). 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).
In Section
Meditations
|
|