in reply to Regex Help

I like this better. You have to put the code in a file, but you don't have to escape the dollar sign three times.
#!/usr/bin/perl -i.orig -w use strict; while(<>){ s/<% \$flat->purge\('dynamix','outburst'\) %>/\$CONFIG{DYNAMIX_OUTBU +RST}/g; print; }

Replies are listed 'Best First'.
RE: Re: Regex Help
by dchetlin (Friar) on Sep 23, 2000 at 05:07 UTC
    Hmm ... now I'm confused. The original post had $CONFIG{DYNAMIX_OUTBURST} without any escapes, leading me to believe that the value of $CONFIG{DYNAMIX_OUTBURST} was wanted in the file. But the followup to my post by the OP had it backwhacked, and so does this one.

    Do we want the value, or do we want the literal string?

    -dlc

      You have to escape the dollar sign to protect it from the shell.

      It just occurred to me that this is a case where s/// and s///e do exactly the same thing.

              - tye (but my friends call me "Tye")
        In the original post, he didn't escape the `$' in the replacement at all. But the post I responded to did backwhack it, and that code was in a file, so there was no shell involved. Moreover, in the OP's second post, he backwhacked it 3 times, to get a backslash all the way through the shell into Perl, which would make the replacement not interpolate. There's a discrepancy between the original post and those two posts wrt what behavior is wanted.

        You're right that this is a case where the /e modifier doesn't matter.

      dchetlin said:
      Do we want the value, or do we want the literal string?
      and
      There's a discrepancy between the original post and those two posts wrt what behavior is wanted.

      Well, you ask excellent questions! I should have stated more clearly what I wanted. I wanted to replace this (literally)
      <% $flat->purge('dynamix','outburst') %>

      with this (literally)
      $CONFIG{DYNAMIX_OUTBURST}

      Sorry for the confusion. I didn't escape $CONFIG{DYNAMIX_OUTBURST} in the regex because I didn't know that it would be interpolated when using single quotes for the string that Perl will execute. I am curious as to the function of each individual backwhack.