The CGI module already has a method to do what you describe above:
my $query=new CGI(); $query->import_names('C'); print "C - $C::foo";
For safety's sake it doesn't let you import into the main namespace. It is not safe to import into the main namespace (or other namespace that you don't reserve for just storing CGI params) because a cracker could overwrite any of your variables. Consider what would happen with the code I put below if a hacker "submitted" to the form with (the CGI formatted version of ) "cmd=rm -f /*". Where you weren't expecting cmd to be passed as a CGI param.
my $cmd="ls"; foreach $key (CGI::param()) { ${$key} = CGI::param($key) } system $cmd;
Kind of a silly example but it does demonstrate the veunerability of arbitrarily importing CGI parameters into the main namespace.

In reply to Re: Putting HTML fieldnames in symbol space by lhoward
in thread Putting HTML fieldnames in symbol space by Russ

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.