On Nov 12, 2006, at 3:22 PM, Xavier Noria wrote:

> On Nov 12, 2006, at 8:58 PM, Tom Pollard wrote:
>> Strictly speaking, doesn't it mean "if 'hash' is nil (or false),  
>> assign to a newly created empty hash"?  You're not testing whether  
>> it's actually a hash already.  Also, maybe it's worth reminding  
>> the OP that an empty hash is not treated as 'false' in a logical  
>> expression in Ruby, as it would be in Perl.  So, if you were to  
>> repeatedly evaluate
>>
>>     hash ||= {}
>>
>> you'd only create a new Hash the first time.  In Perl, on the  
>> other hand, repeatedly evaluating the similar expression
>>
>>     $hashref ||= {}
>>
>> would create and assign a new hash repeatedly, until some hash  
>> element was assigned.
>
> Well, in that case there's only one assignment indeed, because a  
> hashref is true in Perl as well:
>
>   $ perl -wle 'do {$h ||= {}; print $h} for 1..3'
>   HASH(0x1800e8c)
>   HASH(0x1800e8c)
>   HASH(0x1800e8c)

Good point.  I confused the ref with the hash.  I'll shut up again,  
now...

Tom