http://www.perlmonks.org?node_id=870830


in reply to Store regular expressions in a file.

If you just wanted to create regular expressions for matching from a file, you could use the qr quoting operator, but don't think that will work for substituting as you appear to want to do - as others have pointed out, you would probably have to use eval for that.

Replies are listed 'Best First'.
Re^2: Store regular expressions in a file.
by Anonymous Monk on Nov 11, 2010 at 11:52 UTC
    I see.

    Thanks

      This also works:

      #!/usr/bin/perl use strict; use warnings; my $data = "duck"; while(<DATA>) { chomp; my( $find, $replace ) = split ' ', $_, 2; if( $data =~ s[\Q$find][$replace]e ) { print "$data\n"; } } __DATA__ duck luck

      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.