28 Oct 2018 21:24:45 UTC
- Distribution: Tie-Subset
- Module version: 0.01
- Source (raw)
- Browse (raw)
- How to Contribute
- Repository (git clone)
- Issues (0)
- Testers (813 / 0 / 0)
- KwaliteeBus factor: 1
- 66.67% Coverage
- License: perl_5
- Perl: v5.6.0
- Activity24 month
- Download (11.01KB)
- MetaCPAN Explorer
- Subscribe to distribution
- This version
- Latest versionHAUKEX Hauke D
Tie::Subset::Array - Tie an array to a subset of another array
use Tie::Subset::Array; my @array = (55,66,77,88,99); tie my @subset, 'Tie::Subset::Array', \@array, [1,2,3]; print "$subset\n"; # prints "77" $subset++; # modifies $array
This class for tied arrays provides a "view" of a subset of an array.
tie my @subset, 'Tie::Subset::Array', \@array, \@indices;
You must specify which subset of indices from the original array should be part of the new array. (Indices that do not yet exist in the original hash may be specified.) The subset (tied array) will be the same size as
@indices, and is indexed by the usual 0 to
If the index is within the bounds of the tied array, the value from the underlying array is returned, otherwise returns nothing (undef).
If the index is within the bounds of the tied array, the new value will be stored in the underlying array, otherwise the operation is ignored and a warning issued.
Note: The Perl documentation strongly discourages from calling exists on array values.
Will return true only if the index
existsin the subset and the corresponding index in the underlying array
- Not Supported
Any operations that modify the size of the tied array are not (yet) supported (because it is ambiguous how such operations should affect the underlying array). Attempting to change the tied array's size, including using
splice, assigning to the
$#arraynotation, clearing the array, etc. will currently do nothing and cause a warning to be issued, and operations that normally return a value will return nothing.
The above is also true for attempting to
deletearray elements, which the Perl documentation strongly discourages anyway.
A future version of this module may lift these limitations (if a useful default behavior exists).
Copyright (c) 2018 Hauke Daempfling (email@example.com).
This library is free software; you can redistribute it and/or modify it under the same terms as Perl 5 itself.