Hi all, I have a set of strings stored in an array, and I want to apply a number of regex substitutions to them. The substitutions are arbitrary and liable to change to I want to store the actual regexes in an array at the top of the script like so...
@name_regexes = qw(s/UDP/PLOP/);
I know theres only one substitution in the above array, but the points is I can't get the following to work:
foreach $string (@strings) {
# Apply each regex
foreach $regex (@name_regexes) {
$name =~ $regex;
push(@names, $name);
}
}
Nothing happens... the string remains untransformed... btw, the @names array that is pushed is to store the transformed strings. The following works fine but is not generic enough as I want to specify regular expressions as I showed earlier:
$name =~ $regex; #is replaced by the following line $name =~ s/UDP/PLOP/;
So my hunch is that is the storing of an entire regex in a string that is the problem - i don't think it is being interpretted by Perl properly... does anyone know/had this problem and how I can fix it??
Best wishes, Arun
In reply to Storing Regular Expressions as Strings in Array?? by arunhorne
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |