Re: [MacPerl-AnyPerl] negative lookahead problem

[email protected] (Ronald J Kimball) Sat, 11 Aug 2001 09:34:18 -0400
Newsgroups perl.macperl.anyperl
Message-ID <[email protected]>
On Sat, Aug 11, 2001 at 03:26:16PM +0200, allan wrote:

> ronald's script works out of the box. but again im not sure i understand
> why. for instance, what is the difference between | and || (precedence
> perhaps?) and why exactly are we using the /e modifier?

The | is part of the pattern.  In this context, it is a regular expression
alternation: match either this or that.

The || is part of the replacement, which is being evaluated as Perl code
because of the /e modifier.  It is a logical or.  The left operand is
evaluated ($1 in this case), and if it's true it is returned.  If it false,
then the right operand (qq{$2"$3"} in this case) is evaluated and returned.

Ronald


> Ronald J Kimball wrote:
> > s{
> >   (<script[^>]*>.*?</script>)   # a script block
> >   |
> >   ([^\s"'<>%()]+=)([^\s"'<>]+)  # an assignment not in a script block
> >  }
> >  {
> >   $1                            # the script block matched
> >   ||
> >   qq{$2"$3"}                    # the assignment match
> >  }xsieg;