Re: question on reference to array slice
- From: Ted Zlatanov <tzz@xxxxxxxxxxxx>
- Date: Mon, 30 Jul 2007 20:20:07 -0400
On Sun, 29 Jul 2007 18:04:28 -0000 Rick <rick.peng.du@xxxxxxxxx> wrote:
R> Hi, guys
R> In C we can store a set of pointers which point to different arrays
R> into an array of pointer. This way we could fast access different
R> array by looking it up in this pointer array. Is there anyway to do
R> this in Perl. I've been trying different things and no luck so far.
R> LIke:
R> @nums = (1 .. 20);
R> I want to store the reference to @nums[1..10] into $data[0], and the
R> reference to @nums[11:20] into $data[1], so that I could visit, for
R> example, the second set of @nums by something like $data[1][5] to get
R> 15.
R> Is this possible for Perl anyway?
It depends on your purpose. If you aim for speed, just use C (Inline::C
for example). Otherwise, to make your own and everyone else's life
easier, use a function to translate the offsets or a constant. Even
better, explain what you're trying to do; it may be that hashes or
multidimensional arrays or array slices are the right answer for you.
Note you don't have to call the offset function every time, only at the
beginning to find out the offset. So it's not a big speed penalty.
Of course, you can always write your own Tie module, but those are IMHO
the last resort.
Ted
.
- References:
- question on reference to array slice
- From: Rick
- question on reference to array slice
- Prev by Date: Re: fork command.
- Next by Date: Re: deleting duplicates in array using references
- Previous by thread: Re: question on reference to array slice
- Next by thread: Perl threads
- Index(es):
Relevant Pages
|
|