On Mon, May 13, 2002 at 10:54:48AM -0500, _brian_d_foy wrote:
> Joe Schaefer points out that values() now works in this case.
>
>
> Index: perlfaq4.pod
> ===================================================================
> RCS file: /cvs/public/perlfaq/perlfaq4.pod,v
> retrieving revision 1.21
> diff -u -d -r1.21 perlfaq4.pod
> --- perlfaq4.pod 6 May 2002 13:08:46 -0000 1.21
> +++ perlfaq4.pod 13 May 2002 15:52:29 -0000
> @@ -1397,9 +1397,10 @@
> }
>
> If you want to do the same thing to modify the values of the hash,
> -you may not use the C<values> function, oddly enough. You need a slice:
> +you can use the C<values> function. The values are not copied,
> +so if you modify $orbit (in this case), you modify the value.
>
> - for $orbit ( @orbits{keys %orbits} ) {
> + for $orbit ( values %orbits ) {
> ($orbit **= 3) *= (4/3) * 3.14159;
> }
As of 5.6. As 5.005 is still out in the wild would it be wise to add after
that something like:
Prior to perl 5.6 C<values> returned copies of the values, so older
perl code often contains constructions such as C<@orbits{keys
%orbits}> instead of C<values %orbits> where the hash is to be modified.
Otherwise people reading a current copy of the FAQ but programming for
5.005_03 or earlier will create buggy code.
Nicholas Clark
--
Even better than the real thing: http://nms-cgi.sourceforge.net/