What is the difference between cmpStr and cmpStrHard in Perl FreezeThaw?

What is the difference between cmpStr and cmpStrHard in FreezeThaw ?

They are mentioned in the FAQ. How to check if two arrays or hashes are equal?

+4
source share
1 answer

The documentation is very vague and the source code is hard to give in, but the example in the FAQ gives some insight. Having studied all of them, I think I understand what functions do and what documentation means.

CmpStr compares serialized representations of two data structures. It returns 0 if they are equivalent. It returns a nonzero value otherwise. (Technically, it returns -1 if the first data structure is less than the second and +1 if it is larger, but the concepts of less and more are not particularly useful for hashes.)

CmpStrHard is similar, but more strict. It returns 0 only if the two data structures are exactly the same.

The difference between equivalence and equality lies in the links that are used to build complex data structures. Consider the following:

 my ($x, $y, $z); $x = [1]; $y = [1]; $z = $y; 

$x and $y equivalent: they are like references to an array that contains a single value of "1". $y and $z more than equivalent, they are equal: they are both references to the same anonymous array. If you say

 $y->[0] = 2; 

then $x and $y will no longer be equivalent, but $y and $z will still be equal.

I believe that when FreezeThaw's documentation says “considered as a group,” it talks about data structures that can contain references to the same objects. (And if so, the freeze / thaw cycle should preserve this relationship.)

+6
source

All Articles