Pierre Mariani wrote:
Hello everyone,I have a 'modify_variable' function that, well, modifies a variable. I want to run it on several variables. I have the following code that: - builds an array of references on the variables, - calls the function on the content of the reference, - set the content of the reference to the result of the function. # $var1, $var2 and $var3 are set previously for ( \$var1, \$var2, \$var3,){ ${$_} = modify_variable ( ${$_} ); } Questions: - How do I improve my array definition?- How to I call the modify_variable function in a more elegant way?
I have a number of problems with this: - It's unclear whether you have a fixed set of variables to process. Is the list always the same? - Why are you using references? Are you sure you need to? - modify_variable() doesn't appear to modify anything, otherwise why are you assigning its return value to the scalar passed as a parameter? It seems to be just a function.
From what I can see, you need no more than:
$_ = function($_) foreach ($var1, $var2, $var3); Will this do? Or is there more to the problem than you've explained? Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
