develooper Front page | perl.perl6.language | Postings from April 2002

Hashes, Stringification, Hashing and Strings

Thread Next
From:
Aaron Sherman
Date:
April 16, 2002 09:16
Subject:
Hashes, Stringification, Hashing and Strings
Message ID:
1018973636.20193.669.camel@pps
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.



Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About