develooper Front page | perl.perl5.porters | Postings from March 2001

[IDEA] FETCHSLICE, STORESLICE tie methods

From:
Jarkko Hietaniemi
Date:
March 31, 2001 10:34
Subject:
[IDEA] FETCHSLICE, STORESLICE tie methods
Message ID:
20010331123343.F8991@chaos.wustl.edu
Currently if you do

	... = @a[...]

	%b{...} = ...

to a tied array or hash, you get several separate FETCHes and STOREs.
For efficiency and/or semantic reasons you might want otherwise.

I propose adding new (optional) methods applicable to both arrays
and hashes, FETCHSLICE and STORESLICE, which are called thusly:

	FETCHSLICE $this @indices
	STORESLICE $this $nindices $nvalues @indices @values

For hashes one can read 'indices' as 'keys' if that feels more natural.

The $indices and $nvalues are needed since the left hand side
and the right hand side are not necessarily of the same length.

For hashes it might make more sense to have

	STORESLICE $this $nindices @keyvalpairs

To get rid of the $nindices and $nvalues one might also consider

	FETCHSLICE $this [@indices]
	STORESLICE $this [@indices] [@values]

but I don't know whether constructing and dereferencing the anon
arrays would be too costly.

Implementation?  Hey, I'm the proposer, okay?

-- 
$jhi++; # http://www.iki.fi/jhi/
        # There is this special biologist word we use for 'stable'.
        # It is 'dead'. -- Jack Cohen



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About