Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Store regular expressions in a file.

by mjscott2702 (Pilgrim)
on Nov 11, 2010 at 11:42 UTC ( [id://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.

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.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (3)
As of 2024-04-19 15:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found