On Fri, 16 Apr 2004, Aaron Sherman wrote:

> > >   @matrix... = <<1 0 0 1>>;

>
> In the case of:
>
>       @matrix = <<1 2 3 4 5>>;
>
> You need only add the type:
>
>       int @matrix = <<1 2 3 4 5>>;

> There is no string phase, or at least should never be.
> The compiler can
> pre-compute the list:
>
>       int @matrix = ('1','2','3','4','5');
>
> And it then has another obvious pre-computation to perform:
>
>       int @matrix = (+'1', +'2', +'3', +'4', +'5');
>
> And since everything is a constant, you end up with:
>
>       int @matrix = (1, 2, 3, 4, 5);
>

This int business may make sense for a one dimensional array, but I meant
@matrix to be 2 dimensional, and hence you'd need something like

my @matrix is Array of Array of Int = <<1 2 3 4 5>>;
# that syntax won't work, obviously, but I do not know how to take slices,
and that was my original question...

It seems to me that trying to get the compiler to do all that for all
sorts of weird constructs is hard, more work than what we get out of it,
and all you'd probably get is something that works for a few special
cases.

In any case, I used <<1 2 3 4 5>> because it is less typing, and I use
stuff like qw{2 3 5 7 11} in P5 all the time.

--Abhijit

Reply via email to