Pavel Smerk schrieb:
> Assume a big hash and/or a nested structure and the need of a plenty 
> of operations on some hash[...][...][...] which is Float. How can one 
> avoid the repetitious evaluation of the indices? I have not been able 
> to get a "real" reference to that variable to do _something_like_ tmp 
> = referenceof(hash[...][...][...]) and work with the value directly 
> through the (dereferenced) tmp variable. In Perl I would say
>
> $ perl -e '$x[1][2][3] = 1; $a = \$x[1][2][3]; $$a = 3; print 
> $x[1][2][3]'
> 3
>
> (where \... is a reference and $ before $a is a dereference).
>
> Morover, why the return value of the assignment is not an l-value? The 
> following is legal in Perl ($x ||= 1) *= 2 --- why it is not legal in 
> Ruby as well?
>
> Thanks, P.
>
>

You can't get references of immediate values like Fixnums or Symbols. If 
you want a reference, the only way you could do is to get a reference to 
the innermost Hash:

irb(main):001:0> hsh = {1 => {2 => {3 => :value}}}
=> {1=>{2=>{3=>:value}}}
irb(main):002:0> hsh[1][2][3]
=> :value
irb(main):003:0> ref = hsh[1][2]
=> {3=>:value}
irb(main):004:0> ref[3] = :xyz
=> :xyz
irb(main):005:0> ref[3]
=> :xyz
irb(main):006:0> hsh[1][2][3]
=> :xyz

 >Morover, why the return value of the assignment is not an l-value? The 
following is legal in Perl ($x ||= 1) *= 2 --- why it is not legal in 
Ruby as well?
You try to assign a value to a Fixnum. The result of $x ||= 1 is 1 (if 
$x is unintitialized) and so your expression would evolve to:
1 = 1 * 2
which is invalid code.

Marvin