Pierre Mariani wrote: > Matthew and Rob, thank you for your replies. > >> - It's unclear whether you have a fixed set of variables to process. >> Is the list always the same? > > Yes, the list is 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. > > Modify_variable modifies its input variable. > > Please correct me if I am wrong. > My understanding is that: > 1) if I do: > my @array = ($a, $b, $c); > for (@array) { $_ = modify_variable($_)} > I am going to modify $array[0], $array[1] and $array[2], and NOT $a, $b, > $c.
Yes because the contents of $a, $b and $c are copied to @array so there is no way that modifying the contents of @array will affect the contents of $a, $b and $c. > 2) if I do: > for ($a, $b, $c) {$_ = modify_variable($_)} > I am going to modify $a, $b, $c, which is good, but if $a, $b, $c are > big I am going to be passing around lots of data. Yes and in your example 1 above you are passing around lots of data twice. If you don't want to pass around a lot of data then use references and change the modify_variable() sub to work with references. John -- Perl isn't a toolbox, but a small machine shop where you can special-order certain sorts of tools at low cost and in short order. -- Larry Wall -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/