in reply to variables for variables
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:you'll see that this bears a startling resemblance to what you've thought of. Don't do it.while (<RECORDS>) { chomp; @values = split /\t/, $_; foreach $v (@values) { $$v++; } }
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 :
the magic in line 4 works like this :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"}
When you do
, 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}.foreach $field(@fieldList){ $$field = $in{'$field'}; }
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.
|
|---|