in reply to Find Replace text with list
I assume the part you're having trouble with is getting the regular expression into a variable and treating it as a regular expression instead of a string. If you read perldoc perlop in the section on "Quote and quote-like operators", you'll find the subsection "Regex Quote-Like Operators" which will help you.
Basically the trick is this: Once you get the regex into a string, you can use the qr operator to turn it into a reference to a regex that you can use just like a regular expression:
$ cat regex_in_str.pl #!/usr/bin/perl use strict; use warnings; my $r = "ab+c*d"; my $rRegex = qr/$r/; for my $t (qw( abcd aabbbd acccd dbca )) { if ($t =~ $rRegex) { print "MATCH: $t\n"; } } $ perl regex_in_str.pl MATCH: abcd MATCH: aabbbd $
So all you need to do is read the name and representation of your regular expression from a file, convert the representation into a reference to a regex and load your array.
...roboticus
When your only tool is a hammer, all problems look like your thumb.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Find Replace text with list
by wa2nlinux (Novice) on Feb 08, 2011 at 02:37 UTC | |
by Anonymous Monk on Feb 08, 2011 at 07:27 UTC | |
by wa2nlinux (Novice) on Feb 09, 2011 at 01:53 UTC | |
by roboticus (Chancellor) on Feb 08, 2011 at 11:07 UTC |