Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Store regular expressions in a file.

by cdarke (Prior)
on Nov 11, 2010 at 10:58 UTC ( #870813=note: print w/ replies, xml ) Need Help??


in reply to Store regular expressions in a file.

this 'data' is a regular expression

No, it is not a regular expression, only the duck is a regular expression. s is a Perl operator. If you can it would be a lot easier to have two columns, the first being the RE pattern ('duck') and the second being the replacement text ('luck') and then read them into variables (using split) - it is perfectly valid (and common) to store an RE in a Perl variable.

Otherwise you will be reduced to doing nasty things like eval, and you don't want to go there.


Comment on Re: Store regular expressions in a file.
Download Code
Replies are listed 'Best First'.
Re^2: Store regular expressions in a file.
by yoda54 (Monk) on Nov 11, 2010 at 11:22 UTC
    So something like this? I don't get any output.

    Thanks

    #!/usr/bin/perl use strict; use warnings; my $data = "duck"; my $r; while(<DATA>) { chomp; my ($x, $y) = split(/\s/, $_); $r->{$x} = qr/$y/; if ($data =~ $r->{"duck"}) { print "$data\n"; } } __DATA__ duck s/duck/luck/

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2015-08-01 00:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (285 votes), past polls