On Tue, 29 Aug 2000 20:21:39 +0800, Kenneth Lee wrote:

>oday this just came up to my mind, we could have a pragma that disable 
>`autovivification' of hash and array keys. Consider the follow code snippet:
>
>  @arr  = ( 0..9 );
>  %hash = ( a=>1, b=>2 );
>
>  {
>    no autovivify;
>    $arr{10}++;  # both are
>    $hash{c}--;  # fatal
>  }
>
>this way we can eliminate the need to tie any variables to special classes 
>and catch invalid accesses.

Would it? Hmmm... One of the problems is with fields of, for example,
objects. There, not just autovivification, but simply access of a
nonexistent field should cause a complaint. That is a problem that your
proposal doesn't solve.

But, there's at least one function where I would want to disable
autovivification: for parameters to exists().

Witness:

        use Data::Dumper;
        unless(exists $hash{foo}{bar}{baz}{quux}) {
            print "Nope.\n";
        }
        print Dumper \%hash;
-->
Nope.
        $VAR1 = {
                  'foo' => {
                             'bar' => {
                                        'baz' => {}
                                      }
                           }
                };


This pollution of my data structures can be pretty annoying. I'd like
this not to ever happen.

Perhaps this should even be extended to all data accesses not in a LHS
context.

-- 
        Bart.

Reply via email to