Peter wrote:

   > >$ref =
   > >  sub{my%k;@k{@{+pop}}=\(@_);splice@_,$_,!$k{$_}for reverse 
   > > 0..@_;\@_}->(@A,\@I);
   > 
   > Oh, well, if I'd known it was *that* succinct...
   > 
   > But... that *does* involve copying; the original poster was talking
   > about huge arrays where copying was actually significant. You've
   > got the list of keys and values in the temporary hash there. It
   > certainly violates the spirit of the request.

Picky, picky, picky. Very well, here's a version that involves absolutely
no copying of elements or indices...

-----------cut-----------cut-----------cut-----------cut-----------cut----------

@A = (1..10);   # array

sub sliceref
 {my($i,$o,$k)=(0,0,pop);$i+$o-$k->[$i]?++$o&&splice@_,$i,1:$i++while$i<@_;\@_}

my $ref = sliceref @A, [3..5,9];        # reference to slice

print "@A\n";
print "@$ref\n";

$ref->[1] = 99;

print "@A\n";
print "@$ref\n";

-----------cut-----------cut-----------cut-----------cut-----------cut----------

   
   > Which still seems like a reasonable request.

I'd agree.


   > A reference to a slice in perl 5 yields the list of the references
   > to the slice members. Is that the way it's going to be in perl 6?

I would suspect so, since a slice is a list, not an array.

But, of course, that wouldn't preclude a different syntax for generating
a cross-sectional view of an array.

Damian

Reply via email to