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 13:01
Re: [PATCH for discussion] new feature: clamp %hash
Message ID:
>> >   clamp %hash, 0
>> >   clamp %hash, 1
>>     unclamp %hash;
>>     clamp %hash;
>Which would make Jeffrey's other example very tedious:
>	my $prev = clamp %$ref, 0;
>	$ref->{NewKey} = 1;
>	clamp %$ref, $prev;
>	my $prev = clamped %$ref;
>	unclamp %$ref;
>	$ref->{NewKey} = 1;
>	$prev and clamp %$ref;

	Hmm.. if "clamp" and "unclamp" return a reference to the supplied
hash, one could have:

    my $prev = clamped %$ref;
    (unclamp %$ref)->{NewKey} = 1;
    clamp %$ref if $prev;

The "if" instead of "and" looks more natural, doesn't it?  You could
add parens if you worry about precedence problems.  Of course, it's
pretty unnatural to pass in a hash, and return a reference to that
hash.  Returning the hash itself from "unclamp" leads to, err...

    (\unclamp %$ref)->{NewKey} = 1;

	I don't know, I must be overlooking a better way...

					Craig Milo Rogers

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