I need to create a series of variables (with names like $db) which contain the values associated with their respective keys from the configuration module.
Here is what I'm trying to use; with the right side of that assignment replicating the syntax I'm already using repeatedly and successfully to extract data from my configuration hash. My question then is this: How do I set the variable name to match it without writing a dozen lines of repititious code here.
Update
shmem: or anyone really, if you have a real url for that article, that would be of interest to me. Thanks to all, a no strict refs; statement inside the foreach loop moved me past that one. I'm slowly refactoring a crudgy old but working cgi scripts' subroutines into module methods. Was trying to go the route of change only one thing at a time, ergo wishing to bridge how I coded two years ago before I discovered the wisdom of the monestary with how I code now, with a better understanding of objects and hashes. So far, that 300 line subroutine has served as fodder for one public and two substantive private methods, plus a couple of real short ones.
I'm seeing errors reading:foreach my $config ('db','prefix','template','use_db','list_mail','sub +_method','email_metho d','debug_level','subscription_thanks_copy','campaign_type'){ ${$config} = $supporters_conf::config->{$config}; }
All ideas are appreciated.Can't use string ("db") as a SCALAR ref while "strict refs" in use at +/e6/run/cgi/supporters/MailingList.pm line 124.
-- Hugh
In reply to dynamically creating variables by hesco
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |