Arie Folger wrote:

>Hi,
>
>I am trying to implement a conditional regexp by inserting perl code in a 
>regexp, as per the perlre man page, but am having no success. Anybody know 
>how to fix the code below?
>
>       [afolger@localhost afolger]$ perl -e '
>       > $_ = "abcdefg";
>       > s/bc(?{if (/e/){$a = "hi"}else{$a = "HI"}})e/bc${a}e/;
>       > print $_."\n";
>       > '
>       Sequence (?{...}) not terminated or not {}-balanced at -e line 3, within
>       pattern
>       Sequence (?{...}) not terminated or not {}-balanced before HERE mark in regex
>       m/bc(?{ << HERE if (/ at -e line 3.
>       [afolger@localhost afolger]$
>  
>
The error you see is the result of perl terminating the 'lookup part' of 
the s/// statement with the first slash in 'if (/e/)'. the zero-width 
code execution assertion does not protect against illegal use of the 
bracketing character with in the regular expression. to solve that , 
either escape the slashes in the if expression with a backslash,  or 
change the brackting character of either regular expression (s/// or 
m//) to something else, for example - a pipe.

Another problem I see, is that your code regular expression will always 
fail. as the code execution assertion is a zero-width assertion, 
discarding the code block for a second here, your regular expression 
would look like this :
s/bce/bc${a}e/
which will ofcourse always fail for the input "abcdefg".
you probably wanted to do

s/bc.*(?{if (m|e|){$a = "hi"}else{$a = "HI"}})e/bc${a}e/;


--
Oded Arbel
m-Wise mobile solutions
[EMAIL PROTECTED]

+972-9-9581711 (116)
+972-67-340014

::..
We are stronger than our skin of flesh and metal, for we carry and share a
spectrum of suns and lands that lends us legends as we craft our immortality
and interweave our destinies of water and air, leaving shadows that gather
color of their own, until they outshine the substance that cast them.



=================================================================
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]

Reply via email to