Can't use Perl RE (s///) within (?{})

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

Unfortunately, the program I have is way too complex to post here, but
I wrote a lexical analyzer in Perl which makes heavy use of these code
blocks because it more closely approximates the behavior of lex/flex
than anything else I've found.  I've tried both 5.8.7 and 5.10.0 with
varying results, and I've noticed that when I attempt to call the
regular expression engine inside I get two possible outcomes:

1) Out of memory
2) Segmentation fault

my $macro_text         = qr/^(.*?[^\]\n)
                                   $text = $^N;

                                   #$text_lines = $text =~ s|\\n|\n|
                                   @text_lines = split('\n', $text);

                                   @r = ('MACRO_TEXT', $text, scalar
(@text_lines), 0);

The following attempts to snarf arbitrary replacement text in a
textual macro up to a newline not preceded by a backslash.  One of the
things I need to do is a few transformations according the user guide
like strip the backslashes out of the macro text.  There are a few

I've also noticed that declaring 'my' variables local to these blocks
can cause Perl segfaults etc. as well.  I do realize these code blocks
are experimental, but this simplifies my life quite a bit by allowing
the inline code to make pattern specific calculations before the match
is complete.

Any suggestions you could offer would be much appreciated.



Re: Can't use Perl RE (s///) within (?{})

Quoted text here. Click to load it

I don't think a regex in the code block is going to fly
even if doing the regex from a called sub. I think its more a problem
on the substitution side of s/// that is the problem. Some (re-eval 1) error.

sub strip_stuff {
  my $text = shift;
  $text =~ s/\n/\n/g;
  return $text;

qr /...
(? {
  $text = $^N;
  #$text_lines = $text =~ s|\n|\n|gs;
  $text = strip_stuff ($text);

Within the code block things are very quirky and limited.
For all but the simplest things, this is still part of the regular expression.
So inside a regular expression it would seem doubtfull you can have another
expression. Even the delemiters have to be different just to parse. Have you
tried $text /= 5; ?

In my test, in the code block, my() crashed and any regular expression crashes
thats for sure.

Site Timeline