UPDATE

I misunderstood your request. What you're asking for can be a giant pain to troubleshoot. Therefore, my brain blocked out your real question, and replaced it with something very close syntactically.
Now, I don't know if you know dominus, but he's usually a pretty mellow guy. Very helpful, always cheerful, & etc.. However, allow me to quote from the article myocom showed you :

It turned out that the clods who had written this program had done something like this:
while (<RECORDS>) { chomp; @values = split /\t/, $_; foreach $v (@values) { $$v++; } }
you'll see that this bears a startling resemblance to what you've thought of. Don't do it.

Instead, he suggests

If the original programmers had used a series of hashes instead of stuffing everything into a bunch of global variables, it would never have happened, or at worst it would have been easy to fix. I ended up doing a major overhaul on the program to solve the problem.
Which is what I thought you needed help on. OK? OK.

now, back to the original post


here's one way :

for (a..z) {$in {$_}=int rand(100) }; foreach (keys %in){ print "in $_ is $in{$_}\n"; $$out{$_}=$in{$_} } foreach (keys %$out){print "out $_ is $$out{$_}\n"}
the magic in line 4 works like this :
$out is normally a simple scalar. however, prepending it with another "$" and tacking on the {$_} makes $out a reference to a hash.
That's why we can use %$out in line 6. Using the "%" dereferences $out.
Similarly if we say  $foo=\$bar, $foo is holding a reference to that scalar, it's not a scalar in itself. You can dereference it with $$foo. Also,  $foo=\$bar can be written like  $$foo=$bar, which means "the scalar referenced by $foo set to $bar's value". Make sense?

When you do

foreach $field(@fieldList){ $$field = $in{'$field'}; }
, what you're doing is running through each element in @fieldlist as $field, and overwriting it with a reference to a scalar that's set to $in{'$field'}. Additionally, this doesn't make any sense either, since single quotes never do interpolation. Use double quotes or just get rid of them altogether, like $in{$field}.
Also, use strict and -w.
Finally, what reasons do you have for this reassignation of values? Will you really be transforming each $in variable? Or are you just wanting a temporary place to work with them?

If it's the later, dispense with this idea altogether, and just use %in in place.

Update : also, see tye's nifty-keen explanation of referencing and dereferencing for more details.


In reply to (boo) Re: variables for variables by boo_radley
in thread variables for variables by BigVic

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.