Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Can't use Perl RE (s///) within (?{})

Reply
Thread Tools

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

 
 
Clint O
Guest
Posts: n/a
 
      04-26-2009
Hi:

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|
gs;
@text_lines = split('\n', $text);

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

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

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.

Thanks,

-Clint
 
Reply With Quote
 
 
 
 
sln@netherlands.com
Guest
Posts: n/a
 
      04-27-2009
On Sun, 26 Apr 2009 14:11:54 -0700 (PDT), Clint O <(E-Mail Removed)> wrote:

>Hi:
>
>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|
>gs;
> @text_lines = split('\n', $text);
>
> @r = ('MACRO_TEXT', $text, scalar
>(@text_lines), 0);
> })
> /sx;
>
>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
>others.
>
>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.
>
>Thanks,
>
>-Clint


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);
...
})
/xs



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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Trouble running Perl script from within a Perl script laredotornado@zipmail.com Perl Misc 4 07-29-2011 01:44 PM
FAQ 5.5 How can I use Perl's "-i" option from within a program? PerlFAQ Server Perl Misc 0 04-24-2011 04:00 PM
FAQ 5.5 How can I use Perl's "-i" option from within a program? PerlFAQ Server Perl Misc 0 02-09-2011 11:00 AM
How to use Mozilla within Perl (to replace IE) DG Perl Misc 3 07-30-2004 12:37 PM
embedding perl within perl.... suraj Perl Misc 4 11-07-2003 06:02 PM



Advertisments