In this example:

        %hash = ($a=>$b);

$a can be anything. In fact, since Perl6 promises to retain the original
value of $a, we're rather encouraged to store complex data there. But,
this poses a problem. The key to use for hashing might not ideally be
the string representation.

For example, if I'm hashing a collection of special file objects, it
might be useful in one context to do:

        method operator:qq () {
                return read_whole_file();
        }

But, if I have 100 of these objects, and I try to put them in a hash,
life could get ugly fast!

More helpful would be to have this builtin:

        method operator:hash () {
                return operator:qq();
        }

and then allow me to override it in my class like so:

        method operator:hash () {
                return filename();
        }

This allows me to specify separate hashing and stringification methods,
but retains Perl's original default of combining the two.


Reply via email to