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

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

Thread Previous | Thread Next
From:
Graham Barr
Date:
July 19, 2001 12:21
Subject:
Re: [PATCH for discussion] new feature: clamp %hash
Message ID:
20010719201946.J51129@pobox.com
On Thu, Jul 19, 2001 at 11:43:02AM -0700, Jeffrey Friedl wrote:
> 
> Graham Barr <gbarr@pobox.com> wrote:
> |> I too have often wanted something like this. Currently I do it by a tied
> |> hash, but due to performance only do so when I run my script in a debug
> |> mode.
> 
> I've done this type of thing as well, but it seems that with complex
> systems working on complex data, the debugging doesn't always uncover
> everything.
> 
> |> However I would disagree that reading a non-existant entry should croak.
> 
> My thinking here is that when you create the hash (and I'm mostly thinking
> in a using-a-hash-as-an-object mode), you would pre-create all fields
> you'll ever need:

Thats certainly one way to do it. I am just saying that is not the ONLY way
to do it. And I dont see why Perl should force things.

> If you really want to add another on the fly, you can easily do it with
> 	my $prev = clamp %$ref, 0;
> 	$ref->{NewKey} = 1;
> 	clamp %$ref, $prev;
> 
> (it's just flipping a bit, so is very low impact).

I am OK with adding, thats not my issue. My issue is with reading the hash.

ie

  $var = $hash{element};

should just continue to return undef, not croak. IMO

Graham.

Thread Previous | 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