in reply to Reading Regexes from File
use strict; use warnings; my %substitutions = (); while ( <DATA> ) { chomp; my ($pattern, $replace) = split; my $rxPattern = qr{(?si)$pattern}; $substitutions{$rxPattern} = $replace; } my $str = q{a capital M and Fish}; print qq{$str\n}; $str =~ s{$_}{$substitutions{$_}} for keys %substitutions; print qq{$str\n}; __END__ \s*M\s* MALE \s*F\s* FEMALE
The output produced is
a capital M and Fish a capitalMALEandFEMALEish
I hope this is of use.
Cheers,
JohnGG
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Reading Regexes from File
by jeffthewookiee (Sexton) on Apr 12, 2007 at 18:43 UTC | |
by johngg (Canon) on Apr 12, 2007 at 22:57 UTC |