develooper Front page | perl.perl6.language | Postings from September 2001

Re: Customizable default hash and array values.

Thread Previous | Thread Next
From:
Dan Sugalski
Date:
September 25, 2001 15:53
Subject:
Re: Customizable default hash and array values.
Message ID:
5.1.0.14.2.20010925185127.02a0d508@63.120.19.219
At 10:06 PM 9/24/2001 -0400, Michael G Schwern wrote:
>Wouldn't it be nice if there was a way to change the default value of
>a hash?  So instead of undef you'll get whatever default you like?

Sure, I don't see why not. The hash access function is responsible for 
returning a value, so there's no reason you shouldn't be able to override 
it. Whether that's a core feature now is another issue, of course, but 
there won't be anything to stop you. You can also do trickery to not 
autovivify elements of the array or hash if they're only read and don't exist.

I'm pretty sure you can do this now with tie, but that's kind of heavy-weight.

					Dan

--------------------------------------"it's like this"-------------------
Dan Sugalski                          even samurai
dan@sidhe.org                         have teddy bears and even
                                      teddy bears get drunk


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