in reply to Re: array pre-allocation trick
in thread array pre-allocation trick

Are you sure that trick with array pre-allocating does what you think it does? My short experiment suggests otherwise:

$ perl -le '$#{\my @array}=100;print scalar @array' 0 $ perl -le 'my @array;$#array=100;print scalar @array' 101

Using strict clears things up...

$ perl -le 'use strict;$#{\my @array}=100;print scalar @array' Global symbol "@array" requires explicit package name at -e line 1. Execution of -e aborted due to compilation errors.

The my lexically scopes @array to the block which you then use as a reference.

-sauoq
"My two cents aren't worth a dime.";