Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Re: Store regular expressions in a file.

by mjscott2702 (Pilgrim)
on Nov 11, 2010 at 11:42 UTC ( #870830=note: print w/ replies, xml ) Need Help??

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.
Comment on Re: Store regular expressions in a file.
Select or Download Code
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.


      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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://870830]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (2)
As of 2016-05-01 16:21 GMT
Find Nodes?
    Voting Booth?

    No recent polls found