On Mon, 11 Sep 2000, Myers, Dirk wrote:

> >Suppose you could specify the value with which all variables
> >in the enclosing scope should be initialized; for example:
> 
> I haven't seen this either, but I suggest that it should be a set of
> pragmas:
> use init_scalar 0 ;
> use init_array () ;
> 
> ... especially because I'm not sure what effect :
> 
>       init_vars = \{} ;
> 
>       my @foo ;
> 
> should have.  (Probably none, but how do you specify default values if you
> want to init multiple kinds of data in the same scope?)


        My suggestion would be that it simply have no effect.  On the
other hand, if a "initial size" attribute were added to arrays, then this
could be very useful...say that you have 50 employees, each of whose data
is stored in a hash.  Here's an easy way to get a list of references to
all the hashes, with error handling built in:

        init_vars \{name => 'NONE'};
        my @employees : size 50;  # 50 entries, each a ref to 1 elem. hash
        @employees = get_from_db('*');
        for (@employees) {
                if ( $_{name} eq 'NONE' ) {
                        die "Oops!  DB error\n";
                }
        }


                                Dave


Reply via email to