Re: question on reference to array slice
- From: "John W. Krahn" <dummy@xxxxxxxxxxx>
- Date: Sun, 29 Jul 2007 21:09:35 GMT
Rick wrote:
In C we can store a set of pointers which point to different arrays
into an array of pointer. This way we could fast access different
array by looking it up in this pointer array. Is there anyway to do
this in Perl. I've been trying different things and no luck so far.
LIke:
@nums = (1 .. 20);
I want to store the reference to @nums[1..10] into $data[0], and the
reference to @nums[11:20] into $data[1], so that I could visit, for
example, the second set of @nums by something like $data[1][5] to get
15.
$ perl -le'
@nums = 1 .. 20;
print "@nums";
$data[ 0 ] = [ \@nums[ 0 .. 9 ] ];
$data[ 1 ] = [ \@nums[ 10 .. 19 ] ];
print ${ $data[ 1 ][ 5 ] };
${ $data[ 1 ][ 5 ] } = 0;
print "@nums";
'
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
16
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 0 17 18 19 20
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
.
- Follow-Ups:
- Re: question on reference to array slice
- From: Mirco Wahab
- Re: question on reference to array slice
- References:
- question on reference to array slice
- From: Rick
- question on reference to array slice
- Prev by Date: Re: Objects/Structures in Perl
- Next by Date: Re: question on reference to array slice
- Previous by thread: Re: question on reference to array slice
- Next by thread: Re: question on reference to array slice
- Index(es):
Relevant Pages
|
|