in reply to REGEX: muliple search and replace

I'm betting there's some cool way of doing:
s/<!--var(\d+)-->/$var_vals{$1}/eg
where %var_vals (probably an array'd work but ...) is filled w/ your varX's values ahead of time. I'm (blush) not sure, or rather, doubt the /e is needed (if it *is* the 'execute the RHS' flag - another blush. Where is my cheatbook?) but that may be what you want.

a

Replies are listed 'Best First'.
RE: RE: REGEX: muliple search and replace
by floopy (Sexton) on Nov 15, 2000 at 02:26 UTC
    I'm not necessarily suggesting you do this, but if your variables are, say, $name, $email, etc. (i.e. they aren't in hashes) you can use symbolic references:
    s/<!--var (\w+)-->/${"main::$1"}/eg
    (so <!--var foo--> would be replaced by the contents of $foo.)

    The only real advantage to punk music is that nobody can whistle it.