OK. I'm stumped on this one.

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.

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}; }
I'm seeing errors reading:

Can't use string ("db") as a SCALAR ref while "strict refs" in use at +/e6/run/cgi/supporters/MailingList.pm line 124.
All ideas are appreciated.

-- Hugh

if( $lal && $lol ) { $life++; }

In reply to dynamically creating variables by hesco

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.