in reply to Re: Re: Re: Re: Re: Re: Re: the search string and me
in thread the search string and me

Ah but your templating system is using global variables for the substitution, which is why it doesn't work with a hash. If you see "$(things)" you try and replace it with the contents of $things. And that's using symbolic references, which is a bad idea. See these 3 posts by dominus for an explanation why symbolic references are a very bad idea, in general. The moral of it is that it's very easy for them to clash with vital variables for your program. It's like driving a car with your passengers seated on your engine.

Why don't you build your templating system around a hash? Store every value you ever want to use in one hash, let's call it %var, and do the substitution like this:

$fld =~ s/\$(\w+)/$var{$1}/g;
Dead easy. You can simply use %params as your hash, or copy the desired values to %var first:
%var = (%params, foo => 'this is a new or changed field', bar => 'and + another', greet => 'Hello');
If your template contains "$(greet)" it'll get replaced by "Hello".

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: Re: Re: Re: Re: the search string and me
by wolis (Scribe) on Sep 23, 2003 at 05:02 UTC
    Thats a good idea, instead of converting my hashes into scalars, convert any stray scalars that need displaying back into the hash!

    And I had no idea those fun creatures called hashes, which I dearly love and use with relish, could be concat in such a way:

    %var = (%params, foo => 'this is a new or changed field', bar => 'and + another', greet => 'Hello');
    Thanks!
    ___ /\__\ "What is the world coming to?" \/__/ www.wolispace.com