Dave Storrs wrote:
>
> 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";
> }
> }
I still don't see any compelling benefit for new syntax here.
Old syntax works great.
my @employees = map { { name => 'NONE' } } 1..50;
By the way, regardless of how @employees gets initialized above,
that initialization gets blown away by the next thing you do:
> @employees = get_from_db('*'); # only got 2 records???
Unfortunately, your approach in this particular case is flawed.
You could do something like this, which is ripe for optimizations:
for ( @employees ) {
get_from_db( \$_, '*' );
# may or may not have assigned some fields...
--
John Porter
We're building the house of the future together.