develooper Front page | perl.perl5.porters | Postings from July 2001

Re: [PATCH for discussion] new feature: clamp %hash

Thread Previous | Thread Next
Craig Milo Rogers
July 19, 2001 12:40
Re: [PATCH for discussion] new feature: clamp %hash
Message ID:

>>To clamp down on a hash and disallow access to nonexistant keys:
>>   clamp %hash, 1
>>To unclamp:
>>   clamp %hash, 0
>>To query
>>   my $clamped = clamp %hash;
>    clamp %hash;
>    unclamp %hasn;
>    my $clampishness = clamped %hash;
>	I think that these are cleaner than having the boolean second
>parameter to "clamp".  Otherwise, I'd welcome this feature.

	On the third hand, adressing Graham Barr's concerns, the second
parameter could be more than a boolean:

    clamp %hash, $CLAMP_NONE;		# unclamp

    clamp %hash, $CLAMP_UNDEF;		# clamp, and return undef on reads of
					# unknown keys.

    clamp %hash, $CLAMP_CROAK;		# clamp, and croak on reads of unknown
					# keys.

where $CLAMP_NONE, $CLAMP_UNDEF, and $CLAMP_CROAK could be 0, 1, and
2, respectively.  An appropriate package should be used, or "use
clamp", maybe?  The internal overhead would be two bits per hash
instead of one.

	For extra credit, there could be a way to specify a value to
be returned instead of undef (on a per-hash basis); that adds more
than just two bits of overhead to the internals, of course.

					Craig Milo Rogers

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About