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).


In reply to Re: [OT] Thoughts on Ruby's new absent operator? by Eily
in thread [OT] Thoughts on Ruby's new absent operator? by perlancar

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.