hesco has asked for the wisdom of the Perl Monks concerning the following question:
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: dynamically creating variables
by nedals (Deacon) on Nov 02, 2006 at 07:54 UTC | |
|
Re: dynamically creating variables
by bobf (Monsignor) on Nov 02, 2006 at 07:56 UTC | |
by Anonymous Monk on Nov 02, 2006 at 08:15 UTC | |
|
Re: dynamically creating variables
by shmem (Chancellor) on Nov 02, 2006 at 08:56 UTC | |
|
Re: dynamically creating variables
by Zaxo (Archbishop) on Nov 02, 2006 at 08:29 UTC | |
|
Re: dynamically creating variables
by jbert (Priest) on Nov 02, 2006 at 14:30 UTC | |
|
Re: dynamically creating variables
by fenLisesi (Priest) on Nov 02, 2006 at 07:55 UTC |