in reply to eval string possibilities
One question is whether the regexes in @regexen contain any interpolations or not. The reason it matters is that (IIRC) if they do, and you use such a regex straight-up in a while loop, then it will recompile the regex on each iteration. This is part of why you would use qr// before entering the loop. (Using /o would not be good here because if the while loop was ever entered more than once with different values of @regexen, it would sill only ever compile the patterns once).
One other potential security/behavior issue to be aware of is that you should quotemeta() your regexes unless you intentionally want to allow them to contain regex metacharacters.
Your general question I can't really answer. I don't know of any really useful applications of eval-string. Remember that a lot of what people use eval-string for can be accomplished with some of Perl's more esoteric but less dangerous features, such as typeglobs, symbol-table manipulation, and symbolic references.
Update: What Zaxo said is also true, and of course you could achieve that equally easily with qr// or eval. If possible, try to have it so that the regexes that are more likely to fail appear earlier in your array.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: eval string possibilities
by ysth (Canon) on Nov 22, 2004 at 05:50 UTC |