in reply to Making an array of predifined length with default values
my @array = (0) x 1000;
Even works with lists of arbitrary length, such as my @array = (1, 2, 3) x 100; (which creates 300 elements).
(but memory-wise, it's not better than iteratively filling the elements, maybe even with predeclaring some initial max size with $#array = 1000; to avoid successive automatic resizing...)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Making an array of predifined length with default values
by AnomalousMonk (Archbishop) on Mar 04, 2009 at 14:36 UTC | |
|
Re^2: Making an array of predifined length with default values
by johnvandam (Acolyte) on Mar 04, 2009 at 12:12 UTC |