develooper Front page | | Postings from September 2000

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

Thread Previous | Thread Next
September 11, 2000 03:37
Re: RFC 207 (v1) Array: Efficient Array Loops
Message ID:
Reading through the examples left me wondering about some

>   @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

>   #compute pairwise sum, pairwise product, pairwise difference...
>   @sum = @a[|i;|j;|k;|l] + @b[|i;|j;|k;|l];
>   @prod= @a[|i;|j;|k;|l] * @b[|i;|j;|k;|l];
>   @diff= @a[|i;|j;|k;|l] - @b[|i;|j;|k;|l];

Hm, not sure if I am missing the point of these examples. Is that any
different from the elementwise '+','*','-' apart from being possibly
limited to 4D arrays?

>   #print lots of stuff to the screen.
>   sub foo { print join(',',@_),"\n"; return 0; }
>   $zero[|i;|j;|k;|l;|m;|n;|o;|p] = foo(|i,|j,|k,|l,|m,|n,|o,|p);

Should that be '$zero' or '@zero'?

>   # Sneaky way to generate dot-product:
>   my $dotproduct;
>   { my @temp[|i] = $dotproduct += $a[|i] * $b[|i]; }

Hm, how can this work with lazy evaluation? How is Perl supposed to know
that @temp should be transiently created to increment $dotproduct as a
side effect? Also, doesn't the above syntax seem to be conflicting with
perl context rules since it essentially contains a statement

   @arr = $scalar


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