in reply to Run a variable as a line of code?

Did you try $string =~s/$match/$replace/g;?

You can easily read the $match and $replace values from a file and it is less dangerous than using eval (who knows what someone might have put in that file you just eval-ed?)

CountZero

"If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

Replies are listed 'Best First'.
Re^2: Run a variable as a line of code?
by hardburn (Abbot) on Apr 04, 2006 at 16:39 UTC

    If you're worried about someone putting Bad Things in your data file, then you'd need to worry about ?{CODE} just as much as eval STRING.

    "There is no shame in being self-taught, only in not trying to learn in the first place." -- Atrus, Myst: The Book of D'ni.

Re^2: Run a variable as a line of code?
by CountZero (Bishop) on Apr 05, 2006 at 06:15 UTC
    Indeed, you are right and therefore I said less dangerous as it would be marginally easier to filter out "bad" code or recognize "good" code in my suggested approach than in a file to be eval-ed.

    CountZero

    "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law