fletcher_the_dog has asked for the wisdom of the Perl Monks concerning the following question:
It doesn't quite work how I want it to though. The output appears like this,use strict; sub make_regex_list{ my @regexes; foreach my $strings (@_) { my($regex_string,$options)=@$strings; push @regexes,qr/(?$options)$regex_string/; } return @regexes; } my $string = "Jack Jack John"; # in real code this array would be constructed # from a file my @reStrings=(["jack","ig"],["john","i"]); my @REGEXES=make_regex_list(@reStrings); foreach my $regex (@REGEXES) { $string=~s/$regex/name/; } print $string."\n";
So, it appears the 'i' option works, but not the 'g'. What can I do to get the 'g' option to work? I know I can use eval , but I would like to avoid this. Thanks!"name Jack name"
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Constructing a list of regexes
by Enlil (Parson) on Feb 20, 2003 at 21:05 UTC | |
|
Re: Constructing a list of regexes
by webengr (Pilgrim) on Feb 20, 2003 at 21:29 UTC | |
|
Re: Constructing a list of regexes
by fletcher_the_dog (Friar) on Feb 20, 2003 at 22:16 UTC | |
by tall_man (Parson) on Feb 20, 2003 at 22:42 UTC |