in reply to substitue variables from file

There's a module String::Interpolate, but I know of noone who's actually using it.

There's also some trick using eval or related (s///ee), but that could cause more trouble than it solves: it's quite errorprone and, worse, a snakepit of security holes.

It really seems to me like you're trying to create a templating system. There's a very good intro articles on templating systems in Choosing a Templating System. Read that first, and see if you still want to go this route.

Replies are listed 'Best First'.
Re^2: substitue variables from file
by azaria (Beadle) on Oct 29, 2005 at 21:44 UTC
    Hi Bart, The reference article you sent resolved the problem with the s/\$(\w+)/${$1}/g Many thanks !!! azaria
      You don't want to do that. Look up "symbolic references" or "soft references" for more information as to why. For one thing, they won't do variables that have been declared with my, as you would usually do under strictures.

      Much better is to have a hash that contains all the variable names you wish your file to be allowed to used. Then, you would do s/\$(\w+)/$hash{$1}/g;


      My criteria for good software:
      1. Does it work?
      2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?