In perl6 I can create an array of fixed size as so: my @array[5];
How can I then change the size of the array later on to be larger, for instance I want array to be of size 7 now
Thanks
In perl6 I can create an array of fixed size as so: my @array[5];
How can I then change the size of the array later on to be larger, for instance I want array to be of size 7 now
Thanks
You can't change the shape of an already existing shaped array.
To do something like this you can bind the positional variable to a new array.
my @array[5];
@array := my @[7];
I don't think there is a test for switching out a declared shape array in the spec tests ( nor do I think there should be )
A probably safer way is to declare the array without a shape and immediately bind it to an array with the starting shape;
my @array := my @[5];
@array := my @[7];
The reason I say this is safer, is a compiler might do some optimizations that assume it will always have the declared shape.
@array[*-1] => @array[4]
@array[6] => Failure.new(…) # ( or even a compile-time error )