develooper Front page | | Postings from September 2000

Re: RFC 207 (v1) Array: Efficient Array Loops

Thread Previous | Thread Next
Jeremy Howard
September 11, 2000 06:00
Re: RFC 207 (v1) Array: Efficient Array Loops
Message ID:
000701c01bf0$4e3067b0$ wrote:
> Reading through the examples left me wondering about some
> technicalities:
> >   @t[|i;|j] = @a[|j;|i];  # transpose 2-d @a
> Written like this it would require that @a is exact 2-dim, i.e. it would
> not just swap the first two dims of any n-dim array? I suppose if I'd
> want that I'd write
>     @t[|i;|j;] = @a[|j;|i;]; # trailing ';' implies there might be
> trailing dims
Not necessary. Since arrays support all the syntax of a plain old list of
lists, and the |i syntax just creates an implicit loop, the example quoted
from the RFC will work with other sized arrays. In fact, if it was only 2d,
it would more properly be:

  $t[|i;|j] = $a[|j;|i];  # transpose 2-d @a

With three dimensions, each implicit loop in

  @t[|i;|j] = @a[|j;|i];  # transpose 2-d @a

is assigning the _list_ (or 1d array) at @a[|j;|i] to the appropriate index
in @t. Ditto for >3 dimensions, except that it is a >1d array (or LOL) that
is being assigned at each index through the implicit loop.

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About