in reply to Re: Re: Regular expression question
in thread Regular expression question

#!/usr/bin/perl use strict; use warnings; undef $/; $_ = <DATA>; my %repl = qw / < &lt; > &gt; foo bar bar foo /; s/(<\s*br\s*>|[<>]|foo|bar)/$repl{$1}||$1/ge; print; __DATA__ <br> Don't do the regex < br > Don't do the regex < br> Don't do the regex <br > Don't do the regex <this> Do the regex <is> Do the regex <a> Do the regex <test> Do the regex <this is a test> Do the regex <br> Don't do the regex < br > Don't do the regex < br> Don't do the regex <br > Don't do the regex &lt;this&gt; Do the regex &lt;is&gt; Do the regex &lt;a&gt; Do the regex &lt;test&gt; Do the regex &lt;this is a test&gt; Do the regex

Abigail

Replies are listed 'Best First'.
Re: Re: Regular expression question
by TASdvlper (Monk) on Jan 16, 2004 at 19:16 UTC
    What does this part do:
    $repl{$1}||$1/ge;
    I know the 'g' is global but I couldn't find what the 'e' is. Also, I couldn't find any info for the '||'.

    Thanks in advance.

      I couldn't find what the 'e' is
      It's in man perlop.
      Also, I couldn't find any info for the '||'.
      Amazingly, that's also in man perlop.

      Abigail

        Let's see if I did my homework right.

        An "/e" will cause the replacement portion to be treated as a full-fledge Perl expression and evaluated right then and there.

        An "||" Logical "OR" if the left expression true, then right is never evaluated.

        I think I got a handle on it now. Thanks for the pointers and making me do the homework ;-)