in reply to Can "delayed-regex assertions" be nested...

I assume that you have read perlre, and the warning there that (??{ ... }) is highly experimental. It's not there without a reason.

I noticed that even a simple regex in a (??{...}) block doesn't work:

#!/usr/bin/perl use strict; use warnings; $_ = "foo"; print "a" =~ m{.} ? "o\n" : "O\n"; if ( m/f (??{ "a" =~ m{.} ? 'o' : 'O' }) o/x){ print "matched\n" } __END__ o

In your position I'd precompute the regex instead of trying to stuff it all in one line.

Replies are listed 'Best First'.
Re^2: Can "delayed-regex assertions" be nested...
by ddn123456 (Pilgrim) on Feb 21, 2008 at 11:29 UTC
    Hi Moritz,

    Thx for the feedback.

    Yes I've read the perlre. Unfortunately my client interpretes highly experimental by default as "Oh. So it's feasible". :-)

    Precomputing the most inner block gives the same result.

    With kind regards.

    DirkDn
      Unfortunately my client interpretes highly experimental by default as "Oh. So it's feasible". :-)

      As a programmer it's your job to tell him otherwise.

      If possible create an example that segfaults (for example try some fun with closures inside the block), and show that to your client ;-)

      Precomputing the most inner block gives the same result.

      Then you have to unroll one more level:

      !/usr/bin/perl use strict; use warnings; use Data::Dumper; my @A = ( "ab", "abcd", "f" ); my %H = ( 'ab' => 0, 'abcd' => 1, #'def' => 2, ); my $re_inner = join( '|', @A); my $re_outer = join '|', grep /$re_inner/gi, keys %H; my @B = grep ( !/$re_outer/gi, @A ); print Dumper(\@B);

      Disclaimer: I haven't actually understood what you try to achieve, maybe there's a better solution altogether.

        Hi,

        Thanks for both suggestions!

        I just told him :-D

        The objective is to get a list all required elements of @a not present in @b while @b may have optional elements.
        The desired client goal is to have this in a fancy grep oneliner for easy hideous copy-pasting across the code snippets.

        The 2 code snippets reach the objective in an "unfancy way".


        @B = grep ( /(??{join( '|', @A)})/gi, keys %H ); @B = grep ( !/(??{join( '|', @B)})/gi, @A ); print "Delta:\n"; print Dumper(@B); foreach $i (@A){if (!(grep (/$i/i, keys %H))){print "$i\n";};};